📄 refclock_palisade.c
字号:
/* * This software was developed by the Software and Component Technologies * group of Trimble Navigation, Ltd. * * Copyright (c) 1997, 1998, 1999, 2000 Trimble Navigation Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Trimble Navigation, Ltd. * 4. The name of Trimble Navigation Ltd. may not be used to endorse or * promote products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY TRIMBLE NAVIGATION LTD. ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL TRIMBLE NAVIGATION LTD. BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *//* * refclock_palisade - clock driver for the Trimble Palisade GPS * timing receiver * * For detailed information on this program, please refer to the html * Refclock 29 page accompanying the NTP distribution. * * for questions / bugs / comments, contact: * sven_dietrich@trimble.com * * Sven-Thorsten Dietrich * 645 North Mary Avenue * Post Office Box 3642 * Sunnyvale, CA 94088-3642 * * Version 2.45; July 14, 1999 * */#ifdef HAVE_CONFIG_H#include "config.h"#endif#if defined(SYS_WINNT)#undef close#define close closesocket#endif#if defined(REFCLOCK) && (defined(PALISADE) || defined(CLOCK_PALISADE))#include "refclock_palisade.h"/* Table to get from month to day of the year */const int days_of_year [12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};#ifdef DEBUGconst char * Tracking_Status[15][15] = { { "Doing Fixes\0" }, { "Good 1SV\0" }, { "Approx. 1SV\0" }, {"Need Time\0" }, { "Need INIT\0" }, { "PDOP too High\0" }, { "Bad 1SV\0" }, { "0SV Usable\0" }, { "1SV Usable\0" }, { "2SV Usable\0" }, { "3SV Usable\0" }, { "No Integrity\0" }, { "Diff Corr\0" }, { "Overdet Clock\0" }, { "Invalid\0" } };#endif/* * Transfer vector */struct refclock refclock_palisade = { palisade_start, /* start up driver */ palisade_shutdown, /* shut down driver */ palisade_poll, /* transmit poll message */ noentry, /* not used */ noentry, /* initialize driver (not used) */ noentry, /* not used */ NOFLAGS /* not used */};int day_of_year P((char *dt));/* Extract the clock type from the mode setting */#define CLK_TYPE(x) ((int)(((x)->ttl) & 0x7F))/* Supported clock types */#define CLK_TRIMBLE 0 /* Trimble Palisade */#define CLK_PRAECIS 1 /* Endrun Technologies Praecis */int praecis_msg;static void praecis_parse(struct recvbuf *rbufp, struct peer *peer);/* * palisade_start - open the devices and initialize data for processing */static intpalisade_start (#ifdef PALISADE unit, peer ) int unit; struct peer *peer;#else /* ANSI */ int unit, struct peer *peer )#endif{ struct palisade_unit *up; struct refclockproc *pp; int fd; char gpsdev[20]; struct termios tio;#ifdef SYS_WINNT (void) sprintf(gpsdev, "COM%d:", unit);#else (void) sprintf(gpsdev, DEVICE, unit);#endif /* * Open serial port. */#if defined PALISADE fd = open(gpsdev, O_RDWR#ifdef O_NONBLOCK | O_NONBLOCK#endif );#else /* NTP 4.x */ fd = refclock_open(gpsdev, SPEED232, LDISC_RAW);#endif if (fd <= 0) {#ifdef DEBUG printf("Palisade(%d) start: open %s failed\n", unit, gpsdev);#endif return 0; } msyslog(LOG_NOTICE, "Palisade(%d) fd: %d dev: %s", unit, fd, gpsdev);#if defined PALISADE tio.c_cflag = (CS8|CLOCAL|CREAD|PARENB|PARODD); tio.c_iflag = (IGNBRK); tio.c_oflag = (0); tio.c_lflag = (0); if (cfsetispeed(&tio, SPEED232) == -1) { msyslog(LOG_ERR,"Palisade(%d) cfsetispeed(fd, &tio): %m",unit);#ifdef DEBUG printf("Palisade(%d) cfsetispeed(fd, &tio)\n",unit);#endif return 0; } if (cfsetospeed(&tio, SPEED232) == -1) {#ifdef DEBUG printf("Palisade(%d) cfsetospeed(fd, &tio)\n",unit);#endif msyslog(LOG_ERR,"Palisade(%d) cfsetospeed(fd, &tio): %m",unit); return 0; }#else /* NTP 4.x */ if (tcgetattr(fd, &tio) < 0) { msyslog(LOG_ERR, "Palisade(%d) tcgetattr(fd, &tio): %m",unit);#ifdef DEBUG printf("Palisade(%d) tcgetattr(fd, &tio)\n",unit);#endif return (0); } tio.c_cflag |= (PARENB|PARODD); tio.c_iflag &= ~ICRNL;#endif /* NTP 4.x */ if (tcsetattr(fd, TCSANOW, &tio) == -1) { msyslog(LOG_ERR, "Palisade(%d) tcsetattr(fd, &tio): %m",unit);#ifdef DEBUG printf("Palisade(%d) tcsetattr(fd, &tio)\n",unit);#endif return 0; } /* * Allocate and initialize unit structure */ up = (struct palisade_unit *) emalloc(sizeof(struct palisade_unit)); if (!(up)) { msyslog(LOG_ERR, "Palisade(%d) emalloc: %m",unit);#ifdef DEBUG printf("Palisade(%d) emalloc\n",unit);#endif (void) close(fd); return (0); } memset((char *)up, 0, sizeof(struct palisade_unit)); up->type = CLK_TYPE(peer); switch (up->type) { case CLK_TRIMBLE: /* Normal mode, do nothing */ break; case CLK_PRAECIS: msyslog(LOG_NOTICE, "Palisade(%d) Praecis mode enabled\n",unit); break; default: msyslog(LOG_NOTICE, "Palisade(%d) mode unknown\n",unit); break; } pp = peer->procptr; pp->io.clock_recv = palisade_io; pp->io.srcclock = (caddr_t)peer; pp->io.datalen = 0; pp->io.fd = fd; if (!io_addclock(&pp->io)) {#ifdef DEBUG printf("Palisade(%d) io_addclock\n",unit);#endif (void) close(fd); free(up); return (0); } /* * Initialize miscellaneous variables */ pp->unitptr = (caddr_t)up; pp->clockdesc = DESCRIPTION; peer->precision = PRECISION; peer->sstclktype = CTL_SST_TS_UHF; peer->minpoll = TRMB_MINPOLL; peer->maxpoll = TRMB_MAXPOLL; memcpy((char *)&pp->refid, REFID, 4); up->leap_status = 0; up->unit = (short) unit; up->rpt_status = TSIP_PARSED_EMPTY; up->rpt_cnt = 0; return 1;}/* * palisade_shutdown - shut down the clock */static voidpalisade_shutdown (#ifdef PALISADE unit, peer ) int unit; struct peer *peer;#else /* ANSI */ int unit, struct peer *peer )#endif{ struct palisade_unit *up; struct refclockproc *pp; pp = peer->procptr; up = (struct palisade_unit *)pp->unitptr; io_closeclock(&pp->io); free(up);}/* * unpack_date - get day and year from date */intday_of_year (#ifdef PALISADE dt ) char * dt;#else char * dt )#endif{ int day, mon, year; mon = dt[1]; /* Check month is inside array bounds */ if ((mon < 1) || (mon > 12)) return -1; day = dt[0] + days_of_year[mon - 1]; year = getint((u_char *) (dt + 2)); if ( !(year % 4) && ((year % 100) || (!(year % 100) && !(year%400))) &&(mon > 2)) day ++; /* leap year and March or later */ return day;}/* * TSIP_decode - decode the TSIP data packets */intTSIP_decode (#ifdef PALISADE peer ) struct peer *peer;#else struct peer *peer )#endif{ int st; long secint; double secs; double secfrac; unsigned short event = 0; struct palisade_unit *up; struct refclockproc *pp; pp = peer->procptr; up = (struct palisade_unit *)pp->unitptr; /* * Check the time packet, decode its contents. * If the timecode has invalid length or is not in * proper format, declare bad format and exit. */ if ((up->rpt_buf[0] == (char) 0x41) || (up->rpt_buf[0] == (char) 0x46) || (up->rpt_buf[0] == (char) 0x54) || (up->rpt_buf[0] == (char) 0x4B) || (up->rpt_buf[0] == (char) 0x6D)) { /* standard time packet - GPS time and GPS week number */#ifdef DEBUG printf("Palisade Port B packets detected. Connect to Port A\n");#endif return 0; } /* * We cast both to u_char to as 0x8f uses the sign bit on a char */ if ((u_char) up->rpt_buf[0] == (u_char) 0x8f) { /* * Superpackets */ event = (unsigned short) (getint((u_char *) &mb(1)) & 0xffff); if (!((pp->sloppyclockflag & CLK_FLAG2) || event)) /* Ignore Packet */ return 0; switch (mb(0) & 0xff) { int GPS_UTC_Offset; case PACKET_8F0B: if (up->polled <= 0) return 0; if (up->rpt_cnt != LENCODE_8F0B) /* check length */ break; #ifdef DEBUGif (debug > 1) { int ts; double lat, lon, alt; lat = getdbl((u_char *) &mb(42)) * R2D; lon = getdbl((u_char *) &mb(50)) * R2D; alt = getdbl((u_char *) &mb(58)); printf("TSIP_decode: unit %d: Latitude: %03.4f Longitude: %03.4f Alt: %05.2f m\n", up->unit, lat,lon,alt); printf("TSIP_decode: unit %d: Sats:", up->unit); for (st = 66, ts = 0; st <= 73; st++) if (mb(st)) { if (mb(st) > 0) ts++; printf(" %02d", mb(st)); } printf(" : Tracking %d\n", ts); }#endif GPS_UTC_Offset = getint((u_char *) &mb(16)); if (GPS_UTC_Offset == 0) { /* Check UTC offset */ #ifdef DEBUG printf("TSIP_decode: UTC Offset Unknown\n");#endif break; } secs = getdbl((u_char *) &mb(3)); secint = (long) secs; secfrac = secs - secint; /* 0.0 <= secfrac < 1.0 */ pp->nsec = (long) (secfrac * 1000000000); secint %= 86400; /* Only care about today */ pp->hour = secint / 3600; secint %= 3600; pp->minute = secint / 60; secint %= 60; pp->second = secint % 60; if ((pp->day = day_of_year(&mb(11))) < 0) break; pp->year = getint((u_char *) &mb(13)); #ifdef DEBUG if (debug > 1) printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%06ld %02d/%02d/%04d UTC %02d\n", up->unit, mb(0) & 0xff, event, pp->hour, pp->minute, pp->second, pp->nsec, mb(12), mb(11), pp->year, GPS_UTC_Offset);#endif /* Only use this packet when no * 8F-AD's are being received */ if (up->leap_status) { up->leap_status = 0; return 0; } return 2; break; case PACKET_NTP: /* Palisade-NTP Packet */ if (up->rpt_cnt != LENCODE_NTP) /* check length */ break; up->leap_status = mb(19); if (up->polled <= 0) return 0; /* Check Tracking Status */ st = mb(18); if (st < 0 || st > 14) st = 14; if ((st >= 2 && st <= 7) || st == 11 || st == 12) {#ifdef DEBUG printf("TSIP_decode: Not Tracking Sats : %s\n", *Tracking_Status[st]);#endif refclock_report(peer, CEVNT_BADTIME); up->polled = -1; return 0; break; } if (up->leap_status & PALISADE_LEAP_PENDING) { if (up->leap_status & PALISADE_UTC_TIME) pp->leap = LEAP_ADDSECOND; else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -