parsenew.html revision 1.1.1.2 1 1.1 kardel <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 1.1 kardel
3 1.1 kardel <html>
4 1.1 kardel
5 1.1 kardel <head>
6 1.1 kardel <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
7 1.1 kardel <title>Making PARSE Clocks</title>
8 1.1 kardel <link href="scripts/style.css" type="text/css" rel="stylesheet">
9 1.1 kardel </head>
10 1.1 kardel
11 1.1 kardel <body>
12 1.1 kardel <h3>How to build new PARSE clocks</h3>
13 1.1 kardel <p>Here is an attempt to sketch out what you need to do in order to add another clock to the parse driver: Currently the implementation is being cleaned up - so not all information in here is completely correct. Refer to the included code where in doubt.</p>
14 1.1 kardel <p>Prerequisites:</p>
15 1.1 kardel <ul>
16 1.1 kardel <li>Does the system you want the clock connect to have the include files termio.h or termios.h ? (You need that for the parse driver)
17 1.1 kardel </ul>
18 1.1 kardel <p>What to do:</p>
19 1.1 kardel <p>Make a conversion module (libparse/clk_*.c)</p>
20 1.1 kardel <ol>
21 1.1 kardel <li>What ist the time code format ?
22 1.1 kardel <ul>
23 1.1 kardel <li>find year, month, day, hour, minute, second, status (synchronised or not), possibly time zone information (you need to give the offset to UTC) You will have to convert the data from a string into a struct clocktime:
24 1.1 kardel <pre>
25 1.1 kardel struct clocktime /* clock time broken up from time code */
26 1.1 kardel {
27 1.1 kardel long day;
28 1.1 kardel long month;
29 1.1 kardel long year;
30 1.1 kardel long hour;
31 1.1 kardel long minute;
32 1.1 kardel long second;
33 1.1 kardel long usecond;
34 1.1 kardel long utcoffset; /* in seconds */
35 1.1 kardel time_t utcoffset; /* true utc time instead of date/time */
36 1.1 kardel long flags; /* current clock status */
37 1.1 kardel };
38 1.1 kardel </pre>
39 1.1 kardel <p>Conversion is usually simple and straight forward. For the flags following values can be OR'ed together:</p>
40 1.1 kardel <pre>
41 1.1 kardel PARSEB_ANNOUNCE switch time zone warning (informational only)
42 1.1 kardel PARSEB_POWERUP no synchronisation - clock confused (must set then)
43 1.1 kardel PARSEB_NOSYNC timecode currently not confirmed (must set then)
44 1.1 kardel usually on reception error when there is still a
45 1.1 kardel chance the the generated time is still ok.
46 1.1 kardel
47 1.1 kardel PARSEB_DST DST in effect (informational only)
48 1.1 kardel PARSEB_UTC timecode contains UTC time (informational only)
49 1.1 kardel PARSEB_LEAPADD LEAP addition warning (prior to leap happening - must set when imminent)
50 1.1 kardel also used for time code that do not encode the
51 1.1 kardel direction (as this is currently the default).
52 1.1 kardel PARSEB_LEAPDEL LEAP deletion warning (prior to leap happening - must set when imminent)
53 1.1 kardel PARSEB_ALTERNATE backup transmitter (informational only)
54 1.1 kardel PARSEB_POSITION geographic position available (informational only)
55 1.1 kardel PARSEB_LEAPSECOND actual leap second (this time code is the leap
56 1.1 kardel second - informational only)
57 1.1 kardel </pre>
58 1.1 kardel <p>These are feature flags denoting items that are supported by the clock:</p>
59 1.1 kardel <pre>
60 1.1 kardel PARSEB_S_LEAP supports LEAP - might set PARSEB_LEAP
61 1.1 kardel PARSEB_S_ANTENNA supports ANTENNA - might set PARSEB_ALTERNATE
62 1.1 kardel PARSEB_S_PPS supports PPS time stamping
63 1.1 kardel PARSEB_S_POSITION supports position information (GPS)
64 1.1 kardel </pre>
65 1.1 kardel <p>If the utctime field is non zero this value will be take as time code value. This allows for conversion routines that already have the utc time value. The utctime field gives the seconds since Jan 1st 1970, 0:00:00. The useconds field gives the respective usec value. The fields for date and time (down to second resolution) will be ignored.</p>
66 1.1 kardel <p>Conversion is done in the cvt_* routine in parse/clk_*.c files. look in them for examples. The basic structure is:</p>
67 1.1 kardel <pre>
68 1.1 kardel struct clockformat <yourclock>_format = {
69 1.1 kardel lots of fields for you to fill out (see below)
70 1.1 kardel };
71 1.1 kardel
72 1.1 kardel static cvt_<yourclock>()
73 1.1 kardel ...
74 1.1 kardel {
75 1.1 kardel if (<I do not recognize my time code>) {
76 1.1 kardel return CVT_NONE;
77 1.1 kardel } else {
78 1.1 kardel if (<conversion into clockformat is ok>) {
79 1.1 kardel <set all necessary flags>;
80 1.1 kardel return CVT_OK;
81 1.1 kardel } else {
82 1.1 kardel return CVT_FAIL|CVT_BADFMT;
83 1.1 kardel }
84 1.1 kardel }
85 1.1 kardel </pre>
86 1.1 kardel <p>The struct clockformat is the interface to the rest of the parse driver - it holds all information necessary for finding the clock message and doing the appropriate time stamping.</p>
87 1.1 kardel <pre>
88 1.1 kardel struct clockformat
89 1.1 kardel {
90 1.1 kardel u_long (*input)();
91 1.1 kardel /* input routine - your routine - cvt_<yourclock> */
92 1.1 kardel u_long (*convert)();
93 1.1 kardel /* conversion routine - your routine - cvt_<yourclock> */
94 1.1 kardel /* routine for handling RS232 sync events (time stamps) - usually sync_simple */
95 1.1 kardel u_long (*syncpps)();
96 1.1 kardel /* PPS input routine - usually pps_one */
97 1.1 kardel void *data;
98 1.1 kardel /* local parameters - any parameters/data/configuration info your conversion
99 1.1 kardel routine might need */
100 1.1 kardel char *name;
101 1.1 kardel /* clock format name - Name of the time code */
102 1.1 kardel unsigned short length;
103 1.1 kardel /* maximum length of data packet for your clock format */
104 1.1 kardel u_long flags;
105 1.1 kardel /* information for the parser what to look for */
106 1.1 kardel };
107 1.1 kardel </pre>
108 1.1 kardel <p>The above should have given you some hints on how to build a clk_*.c file with the time code conversion. See the examples and pick a clock closest to yours and tweak the code to match your clock.</p>
109 1.1 kardel <p>In order to make your clk_*.c file usable a reference to the clockformat structure must be put into parse_conf.c.</p>
110 1.1 kardel </ul>
111 1.1 kardel <li>TTY setup and initialisation/configuration will be done in ntpd/refclock_parse.c.
112 1.1 kardel <ul>
113 1.1 kardel <li>Find out the exact tty settings for your clock (baud rate, parity, stop bits, character size, ...) and note them in terms of termio*.h c_cflag macros.
114 1.1 kardel <li>in ntpd/refclock_parse.c fill out a new the struct clockinfo element (that allocates a new "IP" address - see comments) (see all the other clocks for example)
115 1.1 kardel <pre>
116 1.1 kardel struct clockinfo
117 1.1 kardel {
118 1.1 kardel u_long cl_flags; /* operation flags (io modes) */
119 1.1 kardel PARSE_F_PPSPPS use loopfilter PPS code (CIOGETEV)
120 1.1 kardel PARSE_F_PPSONSECOND PPS pulses are on second
121 1.1 kardel usually flags stay 0 as they are used only for special setups
122 1.1 kardel
123 1.1 kardel void (*cl_poll)(); /* active poll routine */
124 1.1 kardel The routine to call when the clock needs data sent to it in order to
125 1.1 kardel get a time code from the clock (e.g. Trimble clock)
126 1.1 kardel
127 1.1 kardel int (*cl_init)(); /* active poll init routine */
128 1.1 kardel The routine to call for very special initializations.
129 1.1 kardel
130 1.1 kardel void (*cl_event)(); /* special event handling (e.g. reset clock) */
131 1.1 kardel What to do, when an event happens - used to re-initialize clocks on timeout.
132 1.1 kardel
133 1.1 kardel void (*cl_end)(); /* active poll end routine */
134 1.1 kardel The routine to call to undo any special initialisation (free memory/timers)
135 1.1 kardel
136 1.1 kardel void *cl_data; /* local data area for "poll" mechanism */
137 1.1 kardel local data for polling routines
138 1.1 kardel
139 1.1 kardel u_fp cl_rootdelay; /* rootdelay */
140 1.1 kardel NTP rootdelay estimate (usually 0)
141 1.1 kardel
142 1.1 kardel u_long cl_basedelay; /* current offset - unsigned l_fp
143 1.1 kardel fractional part (fraction) by
144 1.1 kardel which the RS232 time code is
145 1.1 kardel delayed from the actual time. */
146 1.1 kardel
147 1.1 kardel u_long cl_ppsdelay; /* current PPS offset - unsigned l_fp fractional
148 1.1 kardel time (fraction) by which the PPS time stamp is delayed (usually 0)
149 1.1 kardel part */
150 1.1 kardel
151 1.1 kardel char *cl_id; /* ID code (usually "DCF") */
152 1.1 kardel Refclock id - (max 4 chars)
153 1.1 kardel
154 1.1 kardel char *cl_description; /* device name */
155 1.1 kardel Name of this device.
156 1.1 kardel
157 1.1 kardel char *cl_format; /* fixed format */
158 1.1 kardel If the data format cann not ne detected automatically this is the name
159 1.1 kardel as in clk_*.c clockformat.
160 1.1 kardel
161 1.1 kardel u_char cl_type; /* clock type (ntp control) */
162 1.1 kardel Type if clock as in clock status word (ntp control messages) - usually 0
163 1.1 kardel
164 1.1 kardel u_long cl_maxunsync; /* time to trust oscillator after losing synch
165 1.1 kardel */
166 1.1 kardel seconds a clock can be trusted after losing synchronisation.
167 1.1 kardel
168 1.1 kardel u_long cl_speed; /* terminal input & output baudrate */
169 1.1 kardel u_long cl_cflag; /* terminal io flags */
170 1.1 kardel u_long cl_iflag; /* terminal io flags */
171 1.1 kardel u_long cl_oflag; /* terminal io flags */
172 1.1 kardel u_long cl_lflag; /* terminal io flags */
173 1.1 kardel termio*.h tty modes.
174 1.1 kardel
175 1.1 kardel u_long cl_samples; /* samples for median filter */
176 1.1 kardel u_long cl_keep; /* samples for median filter to keep */
177 1.1 kardel median filter parameters - smoothing and rejection of bad samples
178 1.1 kardel } clockinfo[] = {
179 1.1 kardel ...,<other clocks>,...
180 1.1 kardel { < your parameters> },
181 1.1 kardel };
182 1.1 kardel
183 1.1 kardel </pre>
184 1.1 kardel </ul>
185 1.1 kardel </ol>
186 1.1 kardel <p>Well, this is very sketchy, i know. But I hope it helps a little bit. The best way is to look which clock comes closest to your and tweak that code.</p>
187 1.1 kardel <p>Two sorts of clocks are used with parse. Clocks that automatically send their time code (once a second) do not need entries in the poll routines because they send the data all the time. The second sort are the clocks that need a command sent to them in order to reply with a time code (like the Trimble clock).</p>
188 1.1.1.2 christos <p>For questions: <a href="mailto:%20kardel AT acm.org">kardel (a] acm.org</a>.</p>
189 1.1 kardel <p>Please include an exact description on how your clock works. (initialisation, TTY modes, strings to be sent to it, responses received from the clock).</p>
190 1.1 kardel <hr>
191 1.1 kardel <script type="text/javascript" language="javascript" src="scripts/footer.txt"></script>
192 1.1 kardel </body>
193 1.1 kardel
194 1.1 kardel <body></body>
195 1.1 kardel
196 1.1.1.2 christos </html>
197