]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ntp/libparse/clk_computime.c
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / contrib / ntp / libparse / clk_computime.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_COMPUTIME)
6 /*
7  * /src/NTP/ntp-4/libparse/clk_computime.c,v 4.6 1999/11/28 09:13:49 kardel RELEASE_19991128_A
8  *
9  * clk_computime.c,v 4.6 1999/11/28 09:13:49 kardel RELEASE_19991128_A
10  * 
11  * Supports Diem's Computime Radio Clock
12  * 
13  * Used the Meinberg clock as a template for Diem's Computime Radio Clock
14  *
15  * adapted by Alois Camenzind <alois.camenzind@ubs.ch>
16  * 
17  * Copyright (C) 1992-1998 by Frank Kardel
18  * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
19  * 
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.
23  * 
24  */
25
26
27 #include <sys/types.h>
28 #include <sys/time.h>
29
30 #include "ntp_fp.h"
31 #include "ntp_unixtime.h"
32 #include "ntp_calendar.h"
33 #include "ntp_stdlib.h"
34
35 #include "parse.h"
36
37 #ifndef PARSESTREAM
38 #include <stdio.h>
39 #else
40 #include "sys/parsestreams.h"
41 extern void printf P((const char *, ...));
42 #endif
43
44 /*
45  * The Computime receiver sends a datagram in the following format every minute
46  * 
47  * Timestamp    T:YY:MM:MD:WD:HH:MM:SSCRLF 
48  * Pos          0123456789012345678901 2 3
49  *              0000000000111111111122 2 2
50  * Parse        T:  :  :  :  :  :  :  rn
51  * 
52  * T    Startcharacter "T" specifies start of the timestamp 
53  * YY   Year MM Month 1-12 
54  * MD   Day of the month 
55  * WD   Day of week 
56  * HH   Hour 
57  * MM   Minute 
58  * SS   Second
59  * CR   Carriage return 
60  * LF   Linefeed
61  * 
62  */
63
64 static struct format computime_fmt =
65 {
66         {
67                 {8, 2},  {5,  2}, {2,  2},      /* day, month, year */
68                 {14, 2}, {17, 2}, {20, 2},      /* hour, minute, second */
69                 {11, 2},                        /* dayofweek,  */
70         },
71         (const unsigned char *)"T:  :  :  :  :  :  :  \r\n",
72         0
73 };
74
75 static u_long cvt_computime P((unsigned char *, int, struct format *, clocktime_t *, void *));
76 static unsigned long inp_computime P((parse_t *, unsigned int, timestamp_t *));
77
78 clockformat_t   clock_computime =
79 {
80         inp_computime,          /* Computime input handling */
81         cvt_computime,          /* Computime conversion */
82         0,                      /* no PPS monitoring */
83         (void *)&computime_fmt, /* conversion configuration */
84         "Diem's Computime Radio Clock", /* Computime Radio Clock */
85         24,                     /* string buffer */
86         0                       /* no private data (complete pakets) */
87 };
88
89 /*
90  * cvt_computime
91  * 
92  * convert simple type format
93  */
94 static          u_long
95 cvt_computime(
96         unsigned char *buffer,
97         int            size,
98         struct format *format,
99         clocktime_t   *clock_time,
100         void          *local
101         )
102 {
103
104         if (!Strok(buffer, format->fixed_string)) { 
105                 return CVT_NONE;
106         } else {
107                 if (Stoi(&buffer[format->field_offsets[O_DAY].offset], &clock_time->day,
108                          format->field_offsets[O_DAY].length) ||
109                     Stoi(&buffer[format->field_offsets[O_MONTH].offset], &clock_time->month,
110                          format->field_offsets[O_MONTH].length) ||
111                     Stoi(&buffer[format->field_offsets[O_YEAR].offset], &clock_time->year,
112                          format->field_offsets[O_YEAR].length) ||
113                     Stoi(&buffer[format->field_offsets[O_HOUR].offset], &clock_time->hour,
114                          format->field_offsets[O_HOUR].length) ||
115                     Stoi(&buffer[format->field_offsets[O_MIN].offset], &clock_time->minute,
116                          format->field_offsets[O_MIN].length) ||
117                     Stoi(&buffer[format->field_offsets[O_SEC].offset], &clock_time->second,
118                          format->field_offsets[O_SEC].length)) { 
119                         return CVT_FAIL | CVT_BADFMT;
120                 } else {
121
122                         clock_time->flags = 0;
123                         clock_time->utcoffset = 0;      /* We have UTC time */
124
125                         return CVT_OK;
126                 }
127         }
128 }
129
130 /*
131  * inp_computime
132  *
133  * grep data from input stream
134  */
135 static u_long
136 inp_computime(
137               parse_t      *parseio,
138               unsigned int  ch,
139               timestamp_t  *tstamp
140               )
141 {
142         unsigned int rtc;
143         
144         parseprintf(DD_PARSE, ("inp_computime(0x%x, 0x%x, ...)\n", (int)parseio, (int)ch));
145         
146         switch (ch)
147         {
148         case 'T':
149                 parseprintf(DD_PARSE, ("inp_computime: START seen\n"));
150                 
151                 parseio->parse_index = 1;
152                 parseio->parse_data[0] = ch;
153                 parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */
154                 return PARSE_INP_SKIP;
155           
156         case '\n':
157                 parseprintf(DD_PARSE, ("inp_computime: END seen\n"));
158                 if ((rtc = parse_addchar(parseio, ch)) == PARSE_INP_SKIP)
159                         return parse_end(parseio);
160                 else
161                         return rtc;
162
163         default:
164                 return parse_addchar(parseio, ch);
165         }
166 }
167
168 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_COMPUTIME) */
169 int clk_computime_bs;
170 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_COMPUTIME) */
171
172 /*
173  * clk_computime.c,v
174  * Revision 4.6  1999/11/28 09:13:49  kardel
175  * RECON_4_0_98F
176  *
177  * Revision 4.5  1998/06/14 21:09:34  kardel
178  * Sun acc cleanup
179  *
180  * Revision 4.4  1998/06/13 12:00:38  kardel
181  * fix SYSV clock name clash
182  *
183  * Revision 4.3  1998/06/12 15:22:26  kardel
184  * fix prototypes
185  *
186  * Revision 4.2  1998/06/12 09:13:24  kardel
187  * conditional compile macros fixed
188  * printf prototype
189  *
190  * Revision 4.1  1998/05/24 09:39:51  kardel
191  * implementation of the new IO handling model
192  *
193  * Revision 4.0  1998/04/10 19:45:27  kardel
194  * Start 4.0 release version numbering
195  *
196  * from V3 1.8 log info deleted 1998/04/11 kardel
197  */