parsenew.html revision 132452
1132451Sroberto<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2132451Sroberto 3132451Sroberto<html> 4132451Sroberto 5132451Sroberto <head> 6132451Sroberto <title>Making PARSE Clocks</title> 7132451Sroberto <link href="scripts/style.css" type="text/css" rel="stylesheet"> 8132451Sroberto </head> 9132451Sroberto 10132451Sroberto <body> 11132451Sroberto <h3>How to build new PARSE clocks</h3> 12132451Sroberto <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> 13132451Sroberto <p>Prerequisites:</p> 14132451Sroberto <ul> 15132451Sroberto <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) 16132451Sroberto </ul> 17132451Sroberto <p>What to do:</p> 18132451Sroberto <p>Make a conversion module (libparse/clk_*.c)</p> 19132451Sroberto <ol> 20132451Sroberto <li>What ist the time code format ? 21132451Sroberto <ul> 22132451Sroberto <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: 23132451Sroberto <pre> 24132451Sroberto struct clocktime /* clock time broken up from time code */ 25132451Sroberto { 26132451Sroberto long day; 27132451Sroberto long month; 28132451Sroberto long year; 29132451Sroberto long hour; 30132451Sroberto long minute; 31132451Sroberto long second; 32132451Sroberto long usecond; 33132451Sroberto long utcoffset; /* in seconds */ 34132451Sroberto time_t utcoffset; /* true utc time instead of date/time */ 35132451Sroberto long flags; /* current clock status */ 36132451Sroberto }; 37132451Sroberto</pre> 38132451Sroberto <p>Conversion is usually simple and straight forward. For the flags following values can be OR'ed together:</p> 39132451Sroberto <pre> 40132451Sroberto PARSEB_ANNOUNCE switch time zone warning (informational only) 41132451Sroberto PARSEB_POWERUP no synchronisation - clock confused (must set then) 42132451Sroberto PARSEB_NOSYNC timecode currently not confirmed (must set then) 43132451Sroberto usually on reception error when there is still a 44132451Sroberto chance the the generated time is still ok. 45132451Sroberto 46132451Sroberto PARSEB_DST DST in effect (informational only) 47132451Sroberto PARSEB_UTC timecode contains UTC time (informational only) 48132451Sroberto PARSEB_LEAPADD LEAP addition warning (prior to leap happening - must set when imminent) 49132451Sroberto also used for time code that do not encode the 50132451Sroberto direction (as this is currently the default). 51132451Sroberto PARSEB_LEAPDEL LEAP deletion warning (prior to leap happening - must set when imminent) 52132451Sroberto PARSEB_ALTERNATE backup transmitter (informational only) 53132451Sroberto PARSEB_POSITION geographic position available (informational only) 54132451Sroberto PARSEB_LEAPSECOND actual leap second (this time code is the leap 55132451Sroberto second - informational only) 56132451Sroberto</pre> 57132451Sroberto <p>These are feature flags denoting items that are supported by the clock:</p> 58132451Sroberto <pre> 59132451Sroberto PARSEB_S_LEAP supports LEAP - might set PARSEB_LEAP 60132451Sroberto PARSEB_S_ANTENNA supports ANTENNA - might set PARSEB_ALTERNATE 61132451Sroberto PARSEB_S_PPS supports PPS time stamping 62132451Sroberto PARSEB_S_POSITION supports position information (GPS) 63132451Sroberto </pre> 64132451Sroberto <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> 65132451Sroberto <p>Conversion is done in the cvt_* routine in parse/clk_*.c files. look in them for examples. The basic structure is:</p> 66132451Sroberto <pre> 67132451Sroberto struct clockformat <yourclock>_format = { 68132451Sroberto lots of fields for you to fill out (see below) 69132451Sroberto }; 70132451Sroberto 71132451Sroberto static cvt_<yourclock>() 72132451Sroberto ... 73132451Sroberto { 74132451Sroberto if (<I do not recognize my time code>) { 75132451Sroberto return CVT_NONE; 76132451Sroberto } else { 77132451Sroberto if (<conversion into clockformat is ok>) { 78132451Sroberto <set all necessary flags>; 79132451Sroberto return CVT_OK; 80132451Sroberto } else { 81132451Sroberto return CVT_FAIL|CVT_BADFMT; 82132451Sroberto } 83132451Sroberto } 84132451Sroberto</pre> 85132451Sroberto <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> 86132451Sroberto <pre> 87132451Srobertostruct clockformat 88132451Sroberto{ 89132451Sroberto u_long (*input)(); 90132451Sroberto /* input routine - your routine - cvt_<yourclock> */ 91132451Sroberto u_long (*convert)(); 92132451Sroberto /* conversion routine - your routine - cvt_<yourclock> */ 93132451Sroberto /* routine for handling RS232 sync events (time stamps) - usually sync_simple */ 94132451Sroberto u_long (*syncpps)(); 95132451Sroberto /* PPS input routine - usually pps_one */ 96132451Sroberto void *data; 97132451Sroberto /* local parameters - any parameters/data/configuration info your conversion 98132451Sroberto routine might need */ 99132451Sroberto char *name; 100132451Sroberto /* clock format name - Name of the time code */ 101132451Sroberto unsigned short length; 102132451Sroberto /* maximum length of data packet for your clock format */ 103132451Sroberto u_long flags; 104132451Sroberto /* information for the parser what to look for */ 105132451Sroberto}; 106132451Sroberto</pre> 107132451Sroberto <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> 108132451Sroberto <p>In order to make your clk_*.c file usable a reference to the clockformat structure must be put into parse_conf.c.</p> 109132451Sroberto </ul> 110132451Sroberto <li>TTY setup and initialisation/configuration will be done in ntpd/refclock_parse.c. 111132451Sroberto <ul> 112132451Sroberto <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. 113132451Sroberto <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) 114132451Sroberto <pre> 115132451Sroberto struct clockinfo 116132451Sroberto { 117132451Sroberto u_long cl_flags; /* operation flags (io modes) */ 118132451Sroberto PARSE_F_PPSPPS use loopfilter PPS code (CIOGETEV) 119132451Sroberto PARSE_F_PPSONSECOND PPS pulses are on second 120132451Sroberto usually flags stay 0 as they are used only for special setups 121132451Sroberto 122132451Sroberto void (*cl_poll)(); /* active poll routine */ 123132451Sroberto The routine to call when the clock needs data sent to it in order to 124132451Sroberto get a time code from the clock (e.g. Trimble clock) 125132451Sroberto 126132451Sroberto int (*cl_init)(); /* active poll init routine */ 127132451Sroberto The routine to call for very special initializations. 128132451Sroberto 129132451Sroberto void (*cl_event)(); /* special event handling (e.g. reset clock) */ 130132451Sroberto What to do, when an event happens - used to re-initialize clocks on timeout. 131132451Sroberto 132132451Sroberto void (*cl_end)(); /* active poll end routine */ 133132451Sroberto The routine to call to undo any special initialisation (free memory/timers) 134132451Sroberto 135132451Sroberto void *cl_data; /* local data area for "poll" mechanism */ 136132451Sroberto local data for polling routines 137132451Sroberto 138132451Sroberto u_fp cl_rootdelay; /* rootdelay */ 139132451Sroberto NTP rootdelay estimate (usually 0) 140132451Sroberto 141132451Sroberto u_long cl_basedelay; /* current offset - unsigned l_fp 142132451Sroberto fractional part (fraction) by 143132451Sroberto which the RS232 time code is 144132451Sroberto delayed from the actual time. */ 145132451Sroberto 146132451Sroberto u_long cl_ppsdelay; /* current PPS offset - unsigned l_fp fractional 147132451Sroberto time (fraction) by which the PPS time stamp is delayed (usually 0) 148132451Sroberto part */ 149132451Sroberto 150132451Sroberto char *cl_id; /* ID code (usually "DCF") */ 151132451Sroberto Refclock id - (max 4 chars) 152132451Sroberto 153132451Sroberto char *cl_description; /* device name */ 154132451Sroberto Name of this device. 155132451Sroberto 156132451Sroberto char *cl_format; /* fixed format */ 157132451Sroberto If the data format cann not ne detected automatically this is the name 158132451Sroberto as in clk_*.c clockformat. 159132451Sroberto 160132451Sroberto u_char cl_type; /* clock type (ntp control) */ 161132451Sroberto Type if clock as in clock status word (ntp control messages) - usually 0 162132451Sroberto 163132451Sroberto u_long cl_maxunsync; /* time to trust oscillator after losing synch 164132451Sroberto */ 165132451Sroberto seconds a clock can be trusted after losing synchronisation. 166132451Sroberto 167132451Sroberto u_long cl_speed; /* terminal input & output baudrate */ 168132451Sroberto u_long cl_cflag; /* terminal io flags */ 169132451Sroberto u_long cl_iflag; /* terminal io flags */ 170132451Sroberto u_long cl_oflag; /* terminal io flags */ 171132451Sroberto u_long cl_lflag; /* terminal io flags */ 172132451Sroberto termio*.h tty modes. 173132451Sroberto 174132451Sroberto u_long cl_samples; /* samples for median filter */ 175132451Sroberto u_long cl_keep; /* samples for median filter to keep */ 176132451Sroberto median filter parameters - smoothing and rejection of bad samples 177132451Sroberto } clockinfo[] = { 178132451Sroberto ...,<other clocks>,... 179132451Sroberto { < your parameters> }, 180132451Sroberto }; 181132451Sroberto 182132451Sroberto</pre> 183132451Sroberto </ul> 184132451Sroberto </ol> 185132451Sroberto <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> 186132451Sroberto <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> 187132451Sroberto <p>For questions: <a href="mailto:%20kardel@acm.org">kardel@acm.org</a>.</p> 188132451Sroberto <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> 189132451Sroberto <hr> 190132451Sroberto <script type="text/javascript" language="javascript" src="scripts/footer.txt"></script> 191132451Sroberto </body> 192132451Sroberto 193132451Sroberto <body></body> 194132451Sroberto 195132451Sroberto</html> 196132451Sroberto