Annotation of embedaddon/ntp/ports/winnt/ntpd/refclock_trimbledc.c, revision 1.1
1.1 ! misho 1: #ifdef HAVE_CONFIG_H
! 2: #include "config.h"
! 3: #endif
! 4:
! 5: #if defined(REFCLOCK) && defined(CLOCK_TRIMBLEDC)
! 6:
! 7: #include "refclock_trimbledc.h"
! 8: extern int debug;
! 9:
! 10: static int trimbledc_start (int, struct peer *);
! 11: static void trimbledc_shutdown (int, struct peer *);
! 12: static void trimbledc_receive (struct recvbuf *);
! 13: static void trimbledc_poll (int, struct peer *);
! 14: static void trimbledc_io (char, int, unsigned char *, l_fp*, struct trimbledc_unit *);
! 15:
! 16:
! 17: /*
! 18: * Transfer vector
! 19: */
! 20: struct refclock refclock_trimbledc = {
! 21: trimbledc_start, /* start up driver */
! 22: trimbledc_shutdown, /* shut down driver */
! 23: trimbledc_poll, /* transmit poll message */
! 24: noentry, /* not used */
! 25: noentry, /* initialize driver (not used) */
! 26: noentry, /* not used */
! 27: NOFLAGS /* not used */
! 28: };
! 29:
! 30:
! 31: /*
! 32: * trimbledc_start - open the devices and initialize data for processing
! 33: */
! 34: static int
! 35: trimbledc_start (
! 36: int unit,
! 37: struct peer *peer
! 38: )
! 39: {
! 40: register struct trimbledc_unit *up;
! 41: struct refclockproc *pp;
! 42: int fd;
! 43: char gpsdev[20];
! 44:
! 45: struct termios tio;
! 46: #ifdef SYS_WINNT
! 47: (void) sprintf(gpsdev, DEVICE, unit);
! 48: #else
! 49: (void) sprintf(gpsdev, DEVICE, unit + 1);
! 50: #endif
! 51: /*
! 52: * Open serial port.
! 53: */
! 54: fd = refclock_open(gpsdev, SPEED232, LDISC_RAW);
! 55: if (fd == -1) {
! 56: msyslog(LOG_ERR,"Trimble (%d) start: open %s failed: %m",
! 57: unit, gpsdev);
! 58: return 0;
! 59: }
! 60:
! 61: msyslog(LOG_NOTICE, "Trimble (%d) fd: %d dev: %s", unit, fd, gpsdev);
! 62:
! 63: if (tcgetattr(fd, &tio) < 0) {
! 64: msyslog(LOG_ERR,
! 65: "Trimble (%d) tcgetattr(fd, &tio): %m",unit);
! 66: return (0);
! 67: }
! 68:
! 69: tio.c_cflag |= (PARENB|PARODD);
! 70: tio.c_iflag &= ~ICRNL;
! 71:
! 72: if (tcsetattr(fd, TCSANOW, &tio) == -1) {
! 73: msyslog(LOG_ERR, "Trimble (%d) tcsetattr(fd, &tio): %m",unit);
! 74: return 0;
! 75: }
! 76:
! 77: /*
! 78: * Allocate and initialize unit structure
! 79: */
! 80: if (!(up = (struct trimbledc_unit *)
! 81: emalloc(sizeof(struct trimbledc_unit)))) {
! 82: (void) close(fd);
! 83: return (0);
! 84: }
! 85: memset((char *)up, 0, sizeof(struct trimbledc_unit));
! 86:
! 87: pp = peer->procptr;
! 88: pp->io.clock_recv = trimbledc_receive;
! 89: pp->io.srcclock = (caddr_t)peer;
! 90: pp->io.datalen = 0;
! 91: pp->io.fd = fd;
! 92:
! 93: if (!io_addclock(&pp->io)) {
! 94: (void) close(fd);
! 95: free(up);
! 96: return (0);
! 97: }
! 98:
! 99: /*
! 100: * Initialize miscellaneous variables
! 101: */
! 102: pp->unitptr = (caddr_t)up;
! 103: pp->clockdesc = DESCRIPTION;
! 104:
! 105: peer->precision = PRECISION;
! 106: peer->sstclktype = CTL_SST_TS_UHF;
! 107: peer->minpoll = TRIMBLEDC_MINPOLL;
! 108: peer->maxpoll = TRIMBLEDC_MAXPOLL;
! 109: memcpy((char *)&pp->refid, REFID, 4);
! 110:
! 111: up->leap_status = 0;
! 112: up->unit = unit;
! 113: up->io_ptr[0] = up->io_ptr[1] = 0;
! 114:
! 115: return 1;
! 116: }
! 117:
! 118:
! 119: /*
! 120: * trimbledc_shutdown - shut down the clock
! 121: */
! 122: static void
! 123: trimbledc_shutdown (
! 124: int unit,
! 125: struct peer *peer
! 126: )
! 127: {
! 128: register struct trimbledc_unit *up;
! 129: struct refclockproc *pp;
! 130: pp = peer->procptr;
! 131: up = (struct trimbledc_unit *)pp->unitptr;
! 132: io_closeclock(&pp->io);
! 133: free(up);
! 134: }
! 135:
! 136:
! 137:
! 138: /*
! 139: * TSIP_decode - decode the TSIP data packets
! 140: */
! 141: static int
! 142: trimbledc_decode (
! 143: struct peer *peer
! 144: )
! 145: {
! 146: #ifdef DEBUG
! 147: double lat, lon, alt;
! 148: #endif
! 149: int st, ts;
! 150: long secint;
! 151: double secs;
! 152: double secfrac;
! 153: unsigned short event = 0;
! 154:
! 155: register struct trimbledc_unit *up;
! 156: struct refclockproc *pp;
! 157:
! 158: pp = peer->procptr;
! 159: up = (struct trimbledc_unit *)pp->unitptr;
! 160:
! 161: /*
! 162: * Check the time packet, decode its contents.
! 163: * If the timecode has invalid length or is not in
! 164: * proper format, declare bad format and exit.
! 165: */
! 166:
! 167: if (up->rpt_buf[0] ==0x41)
! 168: /* standard time packet - GPS time and GPS week number */
! 169: return 0;
! 170:
! 171:
! 172: refclock_report(peer, CEVNT_BADREPLY);
! 173: up->polled = -1;
! 174: #ifdef DEBUG
! 175: if (debug)
! 176: printf("TRIMBLEDC_decode: unit %d: bad packet %02x-%02x event %d len %d\n",
! 177: up->unit, up->rpt_buf[0] & 0xff, mb(0) & 0xff,
! 178: event, up->rpt_cnt);
! 179: #endif
! 180: return 0;
! 181: }
! 182:
! 183: /*
! 184: * trimbledc__receive - receive data from the serial interface
! 185: */
! 186:
! 187: static void
! 188: trimbledc_receive (
! 189: struct recvbuf *rbufp
! 190: )
! 191: {
! 192: register struct trimbledc_unit *up;
! 193: struct refclockproc *pp;
! 194: struct peer *peer;
! 195:
! 196: /*
! 197: * Initialize pointers and read the timecode and timestamp.
! 198: */
! 199: peer = (struct peer *)rbufp->recv_srcclock;
! 200: pp = peer->procptr;
! 201: up = (struct trimbledc_unit *)pp->unitptr;
! 202:
! 203:
! 204: for (;FALSE;) {
! 205: trimbledc_io(pp->sloppyclockflag & CLK_FLAG2, rbufp->recv_length,
! 206: &rbufp->recv_buffer, &pp->lastrec, up);
! 207:
! 208:
! 209:
! 210:
! 211: (void) sprintf(pp->a_lastcode,"%4d %03d %02d:%02d:%02d.%06ld",
! 212: pp->year,pp->day,pp->hour,pp->minute, pp->second,pp->usec);
! 213: pp->lencode = 24;
! 214:
! 215: if (!refclock_process(pp)) {
! 216: refclock_report(peer, CEVNT_BADTIME);
! 217:
! 218: #ifdef DEBUG
! 219: if (debug)
! 220: printf("trimbledc_receive: unit %d: refclock_process failed!\n",
! 221: up->unit);
! 222: #endif
! 223: continue;
! 224: }
! 225:
! 226: record_clock_stats(&peer->srcadr, pp->a_lastcode);
! 227:
! 228: #ifdef DEBUG
! 229: if (debug)
! 230: if (debug)
! 231: printf("trimbledc_receive: unit %d: %s\n",
! 232: up->unit, prettydate(&pp->lastrec));
! 233: #endif
! 234:
! 235: refclock_receive(peer);
! 236: }
! 237: }
! 238:
! 239:
! 240: /*
! 241: * trimbledc_poll - called by the transmit procedure
! 242: *
! 243: */
! 244: static void
! 245: trimbledc_poll (
! 246: int unit,
! 247: struct peer *peer
! 248: )
! 249: {
! 250: struct trimbledc_unit *up;
! 251: struct refclockproc *pp;
! 252:
! 253: pp = peer->procptr;
! 254: up = (struct trimbledc_unit *)pp->unitptr;
! 255:
! 256: pp->polls++;
! 257: if (up->polled > 0) /* last reply never arrived or error */
! 258: refclock_report(peer, CEVNT_TIMEOUT);
! 259:
! 260: up->polled = 2; /* synchronous packet + 1 event */
! 261:
! 262: #ifdef DEBUG
! 263: if (debug)
! 264: printf("trimbledc_poll: unit %d: polling %s\n", unit,
! 265: (pp->sloppyclockflag & CLK_FLAG2) ?
! 266: "synchronous packet" : "event");
! 267: #endif
! 268:
! 269: if (pp->sloppyclockflag & CLK_FLAG2)
! 270: return; /* using synchronous packet input */
! 271:
! 272: // if (HW_poll(pp) < 0)
! 273: refclock_report(peer, CEVNT_FAULT);
! 274: }
! 275:
! 276:
! 277: static void
! 278: trimbledc_io (
! 279: char noevents,
! 280: int buflen, /* bytes in buffer to process */
! 281: unsigned char *bufp, /* receive buffer */
! 282: l_fp* t_in, /* receive time stamp */
! 283: struct trimbledc_unit *up /* pointer to unit data structure */
! 284: )
! 285: {
! 286:
! 287: }
! 288:
! 289:
! 290:
! 291:
! 292: #endif /* REFCLOCK */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>