4 * refclock_tpro - clock driver for the KSI/Odetics TPRO-S IRIG-B reader
11 #if defined(REFCLOCK) && defined(CLOCK_TPRO)
15 #include "ntp_refclock.h"
16 #include "ntp_unixtime.h"
18 #include "ntp_stdlib.h"
24 * This driver supports the KSI/Odetecs TPRO-S IRIG-B reader and TPRO-
25 * SAT GPS receiver for the Sun Microsystems SBus. It requires that the
26 * tpro.o device driver be installed and loaded.
30 * TPRO interface definitions
32 #define DEVICE "/dev/tpro%d" /* device name and unit */
33 #define PRECISION (-20) /* precision assumed (1 us) */
34 #define REFID "IRIG" /* reference ID */
35 #define DESCRIPTION "KSI/Odetics TPRO/S IRIG Interface" /* WRU */
38 * Unit control structure
41 struct tproval tprodata
; /* data returned from tpro read */
47 static int tpro_start
P((int, struct peer
*));
48 static void tpro_shutdown
P((int, struct peer
*));
49 static void tpro_poll
P((int unit
, struct peer
*));
54 struct refclock refclock_tpro
= {
55 tpro_start
, /* start up driver */
56 tpro_shutdown
, /* shut down driver */
57 tpro_poll
, /* transmit poll message */
58 noentry
, /* not used (old tpro_control) */
59 noentry
, /* initialize driver (not used) */
60 noentry
, /* not used (old tpro_buginfo) */
61 NOFLAGS
/* not used */
66 * tpro_start - open the TPRO device and initialize data for processing
74 register struct tprounit
*up
;
75 struct refclockproc
*pp
;
82 (void)sprintf(device
, DEVICE
, unit
);
83 fd
= open(device
, O_RDONLY
| O_NDELAY
, 0777);
85 msyslog(LOG_ERR
, "tpro_start: open of %s: %m", device
);
90 * Allocate and initialize unit structure
92 if (!(up
= (struct tprounit
*) emalloc(sizeof(struct tprounit
)))) {
96 memset((char *)up
, 0, sizeof(struct tprounit
));
98 pp
->io
.clock_recv
= noentry
;
99 pp
->io
.srcclock
= (caddr_t
)peer
;
102 pp
->unitptr
= (caddr_t
)up
;
105 * Initialize miscellaneous peer variables
107 peer
->precision
= PRECISION
;
108 peer
->burst
= NSTAGE
;
109 pp
->clockdesc
= DESCRIPTION
;
110 memcpy((char *)&pp
->refid
, REFID
, 4);
116 * tpro_shutdown - shut down the clock
124 register struct tprounit
*up
;
125 struct refclockproc
*pp
;
128 up
= (struct tprounit
*)pp
->unitptr
;
129 io_closeclock(&pp
->io
);
135 * tpro_poll - called by the transmit procedure
143 register struct tprounit
*up
;
144 struct refclockproc
*pp
;
148 * This is the main routine. It snatches the time from the TPRO
149 * board and tacks on a local timestamp.
152 up
= (struct tprounit
*)pp
->unitptr
;
155 if (read(pp
->io
.fd
, (char *)tp
, sizeof(struct tproval
)) < 0) {
156 refclock_report(peer
, CEVNT_FAULT
);
159 get_systime(&pp
->lastrec
);
163 * We get down to business, check the timecode format and decode
164 * its contents. If the timecode has invalid length or is not in
165 * proper format, we declare bad format and exit. Note: we
166 * can't use the sec/usec conversion produced by the driver,
167 * since the year may be suspect. All format error checking is
168 * done by the sprintf() and sscanf() routines.
170 * Note that the refclockproc usec member has now become nsec.
171 * We could either multiply the read-in usec value by 1000 or
172 * we could pad the written string appropriately and read the
173 * resulting value in already scaled.
175 sprintf(pp
->a_lastcode
,
176 "%1x%1x%1x %1x%1x:%1x%1x:%1x%1x.%1x%1x%1x%1x%1x%1x %1x",
177 tp
->day100
, tp
->day10
, tp
->day1
, tp
->hour10
, tp
->hour1
,
178 tp
->min10
, tp
->min1
, tp
->sec10
, tp
->sec1
, tp
->ms100
,
179 tp
->ms10
, tp
->ms1
, tp
->usec100
, tp
->usec10
, tp
->usec1
,
181 pp
->lencode
= strlen(pp
->a_lastcode
);
184 printf("tpro: time %s timecode %d %s\n",
185 ulfptoa(&pp
->lastrec
, 6), pp
->lencode
,
188 if (sscanf(pp
->a_lastcode
, "%3d %2d:%2d:%2d.%6ld", &pp
->day
,
189 &pp
->hour
, &pp
->minute
, &pp
->second
, &pp
->nsec
)
191 refclock_report(peer
, CEVNT_BADTIME
);
194 pp
->nsec
*= 1000; /* Convert usec to nsec */
195 if (!tp
->status
& 0x3)
196 pp
->leap
= LEAP_NOTINSYNC
;
198 pp
->leap
= LEAP_NOWARNING
;
199 if (!refclock_process(pp
)) {
200 refclock_report(peer
, CEVNT_BADTIME
);
205 if (pp
->coderecv
== pp
->codeproc
) {
206 refclock_report(peer
, CEVNT_TIMEOUT
);
209 refclock_receive(peer
);
210 pp
->lastref
= pp
->lastrec
;
211 record_clock_stats(&peer
->srcadr
, pp
->a_lastcode
);
212 refclock_receive(peer
);
213 peer
->burst
= NSTAGE
;
217 int refclock_tpro_bs
;
218 #endif /* REFCLOCK */