5 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_VARITEXT)
7 * clk_varitext.c,v 1.0 1997/01/19 A.McConnell
9 * Supports Varitext's Radio Clock
11 * Used the Meinberg/Computime clock as a template for Varitext Radio Clock
13 * Copyright (C) 1992-1996 by Frank Kardel
14 * Friedrich-Alexander Universitt Erlangen-Nrnberg, Germany
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE.
23 #include "ntp_unixtime.h"
24 #include "ntp_calendar.h"
29 # include "ntp_stdlib.h"
32 # include "sys/parsestreams.h"
33 extern void printf P((const char *, ...));
36 static const u_char VT_INITIALISED = 0x01;
37 static const u_char VT_SYNCHRONISED = 0x02;
38 static const u_char VT_ALARM_STATE = 0x04;
39 static const u_char VT_BST = 0x08;
40 static const u_char VT_SEASON_CHANGE = 0x10;
41 static const u_char VT_LAST_TELEGRAM_OK = 0x20;
44 * The Varitext receiver sends a datagram in the following format every minute
46 * Timestamp T:YY:MM:MD:WD:HH:MM:SSCRLFSTXXX
47 * Pos 0123456789012345678901 2 3 4567
48 * 0000000000111111111122 2 2 2222
49 * Parse T: : : : : : : \r\n
51 * T Startcharacter "T" specifies start of the timestamp
52 * YY Year MM Month 1-12
61 * Bit 0 - Set= Initialised; Reset=Time Invalid (DO NOT USE)
62 * Bit 1 - Set= Synchronised; Reset= Unsynchronised
63 * Bit 2 - Set= Alarm state; Reset= No alarm
64 * Bit 3 - Set= BST; Reset= GMT
65 * Bit 4 - Set= Seasonal change in approx hour; Reset= No seasonal change expected
66 * Bit 5 - Set= Last MSF telegram was OK; Reset= Last telegram was in error;
69 * XXX Checksum calculated using Fletcher's method (ignored for now).
72 static struct format varitext_fmt =
75 {8, 2}, {5, 2}, {2, 2}, /* day, month, year */
76 {14, 2}, {17, 2}, {20, 2}, /* hour, minute, second */
77 {11, 2}, {24, 1} /* dayofweek, status */
79 (const unsigned char*)"T: : : : : : : \r\n ",
83 static u_long cvt_varitext P((unsigned char *, int, struct format *, clocktime_t *, void *));
84 static u_long inp_varitext P((parse_t *, unsigned int, timestamp_t *));
87 unsigned char start_found;
88 unsigned char end_found;
89 unsigned char end_count;
90 unsigned char previous_ch;
94 clockformat_t clock_varitext =
96 inp_varitext, /* Because of the strange format we need to parse it ourselves */
97 cvt_varitext, /* Varitext conversion */
98 0, /* no PPS monitoring */
99 (void *)&varitext_fmt, /* conversion configuration */
100 "Varitext Radio Clock", /* Varitext Radio Clock */
101 30, /* string buffer */
102 sizeof(struct varitext), /* Private data size required to hold current parse state */
108 * convert simple type format
112 unsigned char *buffer,
114 struct format *format,
115 clocktime_t *clock_time,
120 if (!Strok(buffer, format->fixed_string)) {
123 if (Stoi(&buffer[format->field_offsets[O_DAY].offset], &clock_time->day,
124 format->field_offsets[O_DAY].length) ||
125 Stoi(&buffer[format->field_offsets[O_MONTH].offset], &clock_time->month,
126 format->field_offsets[O_MONTH].length) ||
127 Stoi(&buffer[format->field_offsets[O_YEAR].offset], &clock_time->year,
128 format->field_offsets[O_YEAR].length) ||
129 Stoi(&buffer[format->field_offsets[O_HOUR].offset], &clock_time->hour,
130 format->field_offsets[O_HOUR].length) ||
131 Stoi(&buffer[format->field_offsets[O_MIN].offset], &clock_time->minute,
132 format->field_offsets[O_MIN].length) ||
133 Stoi(&buffer[format->field_offsets[O_SEC].offset], &clock_time->second,
134 format->field_offsets[O_SEC].length)) {
135 return CVT_FAIL | CVT_BADFMT;
137 u_char *f = (u_char*) &buffer[format->field_offsets[O_FLAGS].offset];
139 clock_time->flags = 0;
140 clock_time->utcoffset = 0;
142 if (((*f) & VT_BST)) /* BST flag is set so set to indicate daylight saving time is active and utc offset */
144 clock_time->utcoffset = -1*60*60;
145 clock_time->flags |= PARSEB_DST;
148 if (!((*f) & VT_INITIALISED)) Clock not initialised
149 clock_time->flags |= PARSEB_POWERUP;
151 if (!((*f) & VT_SYNCHRONISED)) Clock not synchronised
152 clock_time->flags |= PARSEB_NOSYNC;
154 if (((*f) & VT_SEASON_CHANGE)) Seasonal change expected in the next hour
155 clock_time->flags |= PARSEB_ANNOUNCE;
169 struct varitext *t = (struct varitext *)parseio->parse_pdata;
172 parseprintf(DD_PARSE, ("inp_varitext(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
175 return PARSE_INP_SKIP; /* local data not allocated - sigh! */
180 if ((t->previous_ch == 'T') && (ch == ':'))
182 parseprintf(DD_PARSE, ("inp_varitext: START seen\n"));
184 parseio->parse_data[0] = 'T';
185 parseio->parse_index=1;
186 parseio->parse_dtime.parse_stime = t->tstamp; /* Time stamp at packet start */
194 if ((rtc = parse_addchar(parseio, ch)) != PARSE_INP_SKIP)
196 parseprintf(DD_PARSE, ("inp_varitext: ABORTED due to too many characters\n"));
198 memset(t, 0, sizeof(struct varitext));
204 if (++(t->end_count) == 4) /* Finally found the end of the message */
206 parseprintf(DD_PARSE, ("inp_varitext: END seen\n"));
208 memset(t, 0, sizeof(struct varitext));
209 if ((rtc = parse_addchar(parseio, 0)) == PARSE_INP_SKIP)
210 return parse_end(parseio);
216 if ((t->previous_ch == '\r') && (ch == '\n'))
225 return PARSE_INP_SKIP;
228 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_VARITEXT) */
230 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_VARITEXT) */
233 * Revision 1.0 1997/06/02 13:16:30 McConnell