File: generic_howto.adoc

package info (click to toggle)
ntpsec 1.2.0%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,044 kB
  • sloc: ansic: 60,737; python: 31,610; sh: 1,494; yacc: 1,291; makefile: 176; javascript: 138
file content (234 lines) | stat: -rw-r--r-- 9,728 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
= How to build new GENERIC clocks
include::include-html.ad[]

Here is an attempt to sketch out what you need to do to add
another clock to the generic 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.

== Prerequisites

* Does the system you want the clock connect to have the include file
termios.h? (You need that for the generic driver)

What to do:

Make a conversion module (libparse/clk_*.c)

== What is the time code format?

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:

-------------------------------------------------------------------------------
struct clocktime                /* clock time broken up from time code */
{
	long day;
	long month;
	long year;
	long hour;
	long minute;
	long second;
	long usecond;
	long utcoffset;       /* in seconds */
	time_t utcoffset;     /* true utc time instead of date/time */
	long flags;           /* current clock status */
};
-------------------------------------------------------------------------------

Conversion is usually simple and straightforward. For the flags
following values can be OR'ed together:

|-------------------------------------------------------------------------------
| PARSEB_ANNOUNCE  | Switch time zone warning (informational only)
| PARSEB_POWERUP   | No synchronisation - clock confused (must set then)
| PARSEB_NOSYNC    | Timecode currently not confirmed (must set then),
                     usually on reception error when there is still a
                     chance the generated time is still ok.
| PARSEB_DST       | DST in effect (informational only)
| PARSEB_UTC       | Timecode contains UTC time (informational only)
| PARSEB_LEAPADD   | LEAP addition warning (prior to leap happening -
                     must set when imminent)
                     Also used for time code that do not encode the
                     direction (as this is currently the default).
| PARSEB_LEAPDEL   | LEAP deletion warning (prior to leap happening -
                     must set when imminent)
| PARSEB_ALTERNATE | Backup transmitter (informational only)
| PARSEB_POSITION  | Geographic position available (informational only)
| PARSEB_LEAPSECOND| Actual leap second (this time code is the leap
                     second - informational only)
|-------------------------------------------------------------------------------

These are feature flags denoting items that are supported by the clock:

|----------------------------------------------------------------------------
| PARSEB_S_LEAP      | supports LEAP - might set PARSEB_LEAP
| PARSEB_S_ANTENNA   | supports ANTENNA - might set PARSEB_ALTERNATE
| PARSEB_S_PPS       | supports PPS time stamping
| PARSEB_S_POSITION  | supports position information (GPS)
|----------------------------------------------------------------------------

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.

Conversion is done in the cvt_* routine in parse/clk_*.c files. Look in
them for examples. The basic structure is:

-----------------------------------------------------
     struct clockformat <yourclock>_format = {
       lots of fields for you to fill out (see below)
     };

     static cvt_<yourclock>()
       ...
     {
       if (<I do not recognize my time code>) {
         return CVT_NONE;
       } else {
         if (<conversion into clockformat is ok>) {
           <set all necessary flags>;
           return CVT_OK;
         } else {
           return CVT_FAIL|CVT_BADFMT;
         }
       }
-----------------------------------------------------

The struct clockformat is the interface to the rest of the generic
driver - it holds all information necessary for finding the clock
message and doing the appropriate time stamping.

--------------------------------------------------------------------------------
struct clockformat
{
  unsigned long (*input)();
  /* input routine - your routine - cvt_<yourclock> */
  unsigned long (*convert)();
  /* conversion routine - your routine - cvt_<yourclock> */
  /* routine for handling RS232 sync events (time stamps) - usually sync_simple */
  unsigned long (*syncpps)();
  /* PPS input routine - usually pps_one */
  void           *data;
  /* local parameters - any parameters/data/configuration info your conversion
     routine might need */
  char           *name;
  /* clock format name - Name of the time code */
  unsigned short  length;
  /* maximum length of data packet for your clock format */
  unsigned long   flags;
 /* information for the parser what to look for */
};
--------------------------------------------------------------------------------

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.

In order to make your clk_*.c file usable, a reference to the clockformat
structure must be put into parse_conf.c.

== Driver initialization

TTY setup and initialization/configuration will be done in
ntpd/refclock_generic.c.

* 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.

* in ntpd/refclock_generic.c fill out a new the struct clockinfo element
(that allocates a new "IP" address - see comments) (see all the other
clocks for example)

--------------------------------------------------------------------------------
struct clockinfo {
        unsigned long  cl_flags;  /* operation flags (io modes) */
         PARSE_F_PPSPPS       use loopfilter PPS code
         PARSE_F_PPSONSECOND  PPS pulses are on second
         usually flags stay 0 as they are used only for special setups

        void  (*cl_poll)();       /* active poll routine */
         The routine to call when the clock needs data sent to it in order to
         get a time code from the clock (e.g., Trimble clock)

        int   (*cl_init)();      /* active poll init routine */
         The routine to call for very special initializations.

        void  (*cl_event)();     /* special event handling (e.g., reset clock) */
         What to do, when an event happens - used to re-initialize clocks on timeout.

        void  (*cl_end)();       /* active poll end routine */
         The routine to call to undo any special initialization (free memory/timers)

        void   *cl_data;        /* local data area for "poll" mechanism */
         local data for polling routines

        u_fp    cl_rootdelay;         /* rootdelay */
         NTP rootdelay estimate (usually 0)

        unsigned long  cl_basedelay;  /* current offset - unsigned l_fp
                                      fractional part (fraction) by
                                      which the RS232 time code is
                                      delayed from the actual time. */

        unsigned long  cl_ppsdelay;   /* current PPS offset - unsigned
                                      l_fp fractional time (fraction)
                                      by which the PPS time stamp is
                                      delayed (usually 0) */

        char   *cl_id;                /* ID code */
         Refclock id - (max 4 chars)

        char   *cl_description;       /* device name */
         Name of this device.

        char   *cl_format;            /* fixed format */
         If the data format can not be detected automatically this is the name
         as in clk_*.c clockformat.

        unsigned char  cl_type;       /* clock type (ntp control) */
         Type if clock as in clock status word (ntp control messages) - usually 0

        unsigned long  cl_maxunsync;  /* time to trust oscillator after
                                         losing synch --  seconds a clock
					 can be trusted after losing
					 synchronisation. */
	unsigned long  cl_speed;      /* terminal input & output baudrate */
	unsigned long  cl_cflag;      /* terminal io flags */
	unsigned long  cl_iflag;      /* terminal io flags */
	unsigned long  cl_oflag;      /* terminal io flags */
	unsigned long  cl_lflag;      /* terminal io flags */

        unsigned long  cl_samples;    /* samples for median filter */
        unsigned long  cl_keep;       /* samples for median filter to keep */
         median filter parameters - smoothing and rejection of bad samples
  } clockinfo[] = {
  ...,<other clocks>,...
  { < your parameters> },
  };
--------------------------------------------------------------------------------

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 yours and tweak that
code.

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).

For questions: mailto:kardel@acm.org[kardel@acm.org].

Please include an exact description on how your clock works.
(initialization, TTY modes, strings to be sent to it, responses received
from the clock).

'''''

include::includes/footer.adoc[]