~ubuntu-branches/debian/squeeze/ntp/squeeze-201010051545

« back to all changes in this revision

Viewing changes to ntpd/refclock_pst.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-10-11 16:10:27 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041011161027-icyjbji8ujym633o
Tags: 1:4.2.0a-10ubuntu2
Use ntp.ubuntulinux.org instead of pool.ntp.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
/*
72
72
 * Interface definitions
73
73
 */
74
 
#define DEVICE          "/dev/pst%d" /* device name and unit */
 
74
#define DEVICE          "/dev/wwv%d" /* device name and unit */
75
75
#define SPEED232        B9600   /* uart speed (9600 baud) */
76
76
#define PRECISION       (-10)   /* precision assumed (about 1 ms) */
77
77
#define WWVREFID        "WWV\0" /* WWV reference ID */
84
84
 * Unit control structure
85
85
 */
86
86
struct pstunit {
87
 
        u_char  tcswitch;       /* timecode switch */
 
87
        int     tcswitch;       /* timecode switch */
88
88
        char    *lastptr;       /* pointer to timecode data */
89
89
};
90
90
 
155
155
         * Initialize miscellaneous variables
156
156
         */
157
157
        peer->precision = PRECISION;
158
 
        peer->burst = NSTAGE;
159
158
        pp->clockdesc = DESCRIPTION;
160
159
        memcpy((char *)&pp->refid, WWVREFID, 4);
 
160
        peer->burst = MAXSTAGE;
161
161
        return (1);
162
162
}
163
163
 
214
214
         * Note we get a buffer and timestamp for each <cr>, but only
215
215
         * the first timestamp is retained.
216
216
         */
217
 
        if (!up->tcswitch)
 
217
        if (up->tcswitch == 0)
218
218
                pp->lastrec = trtmp;
219
219
        up->tcswitch++;
220
220
        pp->lencode = up->lastptr - pp->a_lastcode;
221
221
        if (up->tcswitch < 3)
222
222
                return;
223
 
#ifdef DEBUG
224
 
        if (debug)
225
 
                printf("pst: timecode %d %s\n", pp->lencode,
226
 
                    pp->a_lastcode);
227
 
#endif
228
223
 
229
224
        /*
230
225
         * We get down to business, check the timecode format and decode
240
235
         * Timecode format:
241
236
         * "ahh:mm:ss.fffs yy/dd/mm/ddd frdzycchhSSFTttttuuxx"
242
237
         */
243
 
        if (sscanf(pp->a_lastcode, "%c%2d:%2d:%2d.%3d%c %9s%3d%13s%4ld",
244
 
            &ampmchar, &pp->hour, &pp->minute, &pp->second,
245
 
            &pp->msec, &daychar, junque, &pp->day,
246
 
            info, &ltemp) != 10) {
 
238
        if (sscanf(pp->a_lastcode,
 
239
            "%c%2d:%2d:%2d.%3ld%c %9s%3d%13s%4ld",
 
240
            &ampmchar, &pp->hour, &pp->minute, &pp->second, &pp->nsec,
 
241
            &daychar, junque, &pp->day, info, &ltemp) != 10) {
247
242
                refclock_report(peer, CEVNT_BADREPLY);
248
243
                return;
249
244
        }
 
245
        pp->nsec *= 1000000;
250
246
 
251
247
        /*
252
248
         * Decode synchronization, quality and last update. If
263
259
                memcpy((char *)&pp->refid, WWVREFID, 4);
264
260
        if (peer->stratum <= 1)
265
261
                peer->refid = pp->refid;
266
 
        pp->disp = PST_PHI * ltemp;
 
262
        if (ltemp == 0)
 
263
                pp->lastref = pp->lastrec;
 
264
        pp->disp = PST_PHI * ltemp * 60;
267
265
 
268
266
        /*
269
267
         * Process the new sample in the median filter and determine the
290
288
        /*
291
289
         * Time to poll the clock. The PSTI/Traconex clock responds to a
292
290
         * "QTQDQMT" by returning a timecode in the format specified
293
 
         * above. If nothing is heard from the clock for two polls,
294
 
         * declare a timeout and keep going.
 
291
         * above. Note there is no checking on state, since this may not
 
292
         * be the only customer reading the clock. Only one customer
 
293
         * need poll the clock; all others just listen in. If the clock
 
294
         * becomes unreachable, declare a timeout and keep going.
295
295
         */
296
296
        pp = peer->procptr;
297
297
        up = (struct pstunit *)pp->unitptr;
299
299
        up->lastptr = pp->a_lastcode;
300
300
        if (write(pp->io.fd, "QTQDQMT", 6) != 6)
301
301
                refclock_report(peer, CEVNT_FAULT);
302
 
        else
303
 
                pp->polls++;
304
302
        if (peer->burst > 0)
305
303
                return;
306
304
        if (pp->coderecv == pp->codeproc) {
307
305
                refclock_report(peer, CEVNT_TIMEOUT);
308
306
                return;
309
307
        }
 
308
        refclock_receive(peer);
310
309
        record_clock_stats(&peer->srcadr, pp->a_lastcode);
311
 
        refclock_receive(peer);
312
 
        peer->burst = NSTAGE;
 
310
#ifdef DEBUG
 
311
        if (debug)
 
312
                printf("pst: timecode %d %s\n", pp->lencode,
 
313
                    pp->a_lastcode);
 
314
#endif
 
315
        peer->burst = MAXSTAGE;
 
316
        pp->polls++;
313
317
}
314
318
 
315
319
#else