From: Harlan Stenn Date: Wed, 31 Jan 2007 00:44:35 +0000 (-0500) Subject: re-indent/cleanup refclock_palisade.c X-Git-Tag: NTP_4_2_5P5~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51776449632768fc83d4b04bf44af1765c671a0f;p=thirdparty%2Fntp.git re-indent/cleanup refclock_palisade.c bk: 45bfe6733tiaRl3WeGVDgzpUe4qPlA --- diff --git a/ntpd/refclock_palisade.c b/ntpd/refclock_palisade.c index 31ed89efc..094acbc62 100644 --- a/ntpd/refclock_palisade.c +++ b/ntpd/refclock_palisade.c @@ -65,15 +65,15 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #if defined(SYS_WINNT) -#undef close -#define close closesocket +# undef close +# define close closesocket #endif -#if defined(REFCLOCK) && (defined(PALISADE) || defined(CLOCK_PALISADE)) +#if defined(REFCLOCK) && defined(CLOCK_PALISADE) #include "refclock_palisade.h" /* Table to get from month to day of the year */ @@ -83,11 +83,11 @@ const int days_of_year [12] = { #ifdef DEBUG const 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" } }; + { "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 /* @@ -125,7 +125,8 @@ static void praecis_parse(struct recvbuf *rbufp, struct peer *peer); */ static void sendcmd ( - struct packettx *buffer, int c + struct packettx *buffer, + int c ) { buffer->data[0] = DLE; @@ -138,7 +139,9 @@ sendcmd ( */ static void sendsupercmd ( - struct packettx *buffer, int c1, int c2 + struct packettx *buffer, + int c1, + int c2 ) { buffer->data[0] = DLE; @@ -152,7 +155,8 @@ sendsupercmd ( */ static void sendbyte ( - struct packettx *buffer, int b + struct packettx *buffer, + int b ) { if (b == DLE) @@ -165,7 +169,8 @@ sendbyte ( */ static void sendint ( - struct packettx *buffer, int a + struct packettx *buffer, + int a ) { sendbyte(buffer, (unsigned char)((a>>8) & 0xff)); @@ -177,7 +182,8 @@ sendint ( */ static int sendetx ( - struct packettx *buffer, int fd + struct packettx *buffer, + int fd ) { int result; @@ -222,16 +228,9 @@ init_thunderbolt ( */ static int palisade_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; @@ -247,15 +246,7 @@ palisade_start ( /* * 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); @@ -266,27 +257,6 @@ palisade_start ( 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); @@ -298,7 +268,6 @@ palisade_start ( tio.c_cflag |= (PARENB|PARODD); tio.c_iflag &= ~ICRNL; -#endif /* NTP 4.x */ /* * Allocate and initialize unit structure @@ -318,19 +287,21 @@ palisade_start ( 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; - case CLK_THUNDERBOLT: - msyslog(LOG_NOTICE, "Palisade(%d) Thunderbolt mode enabled\n",unit); - tio.c_cflag = (CS8|CLOCAL|CREAD); - break; - default: - msyslog(LOG_NOTICE, "Palisade(%d) mode unknown\n",unit); - break; + case CLK_TRIMBLE: + /* Normal mode, do nothing */ + break; + case CLK_PRAECIS: + msyslog(LOG_NOTICE, "Palisade(%d) Praecis mode enabled\n" + ,unit); + break; + case CLK_THUNDERBOLT: + msyslog(LOG_NOTICE, "Palisade(%d) Thunderbolt mode enabled\n" + ,unit); + tio.c_cflag = (CS8|CLOCAL|CREAD); + break; + default: + msyslog(LOG_NOTICE, "Palisade(%d) mode unknown\n",unit); + break; } if (tcsetattr(fd, TCSANOW, &tio) == -1) { msyslog(LOG_ERR, "Palisade(%d) tcsetattr(fd, &tio): %m",unit); @@ -383,16 +354,9 @@ palisade_start ( */ static void palisade_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; @@ -409,29 +373,23 @@ palisade_shutdown ( */ int day_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)) + /* 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 */ + (!(year % 100) && !(year%400))) + &&(mon > 2)) + day ++; /* leap year and March or later */ return day; } @@ -442,14 +400,8 @@ day_of_year ( */ int TSIP_decode ( -#ifdef PALISADE - peer - ) - struct peer *peer; -#else struct peer *peer ) -#endif { int st; long secint; @@ -470,349 +422,353 @@ TSIP_decode ( */ if (up->type != CLK_THUNDERBOLT){ - 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)) { + 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 */ + /* 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; - } + return 0; + } } -#endif /* * 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 */ + /* + * 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; - long tow; + switch (mb(0) & 0xff) { + int GPS_UTC_Offset; + long tow; - case PACKET_8F0B: + case PACKET_8F0B: - if (up->polled <= 0) - return 0; + if (up->polled <= 0) + return 0; - if (up->rpt_cnt != LENCODE_8F0B) /* check length */ - break; + if (up->rpt_cnt != LENCODE_8F0B) /* check length */ + break; #ifdef DEBUG -if (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); - } + if (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 */ + 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"); + printf("TSIP_decode: UTC Offset Unknown\n"); #endif - break; - } + break; + } - secs = getdbl((u_char *) &mb(3)); - secint = (long) secs; - secfrac = secs - secint; /* 0.0 <= secfrac < 1.0 */ + secs = getdbl((u_char *) &mb(3)); + secint = (long) secs; + secfrac = secs - secint; /* 0.0 <= secfrac < 1.0 */ - pp->nsec = (long) (secfrac * 1000000000); + 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; + 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; + if ((pp->day = day_of_year(&mb(11))) < 0) break; - pp->year = getint((u_char *) &mb(13)); + 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); + 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 - */ + /* Only use this packet when no + * 8F-AD's are being received + */ - if (up->leap_status) { - up->leap_status = 0; - return 0; - } + if (up->leap_status) { + up->leap_status = 0; + return 0; + } - return 2; - break; + return 2; + break; - case PACKET_NTP: - /* Palisade-NTP Packet */ + case PACKET_NTP: + /* Palisade-NTP Packet */ - if (up->rpt_cnt != LENCODE_NTP) /* check length */ - break; + if (up->rpt_cnt != LENCODE_NTP) /* check length */ + break; - up->leap_status = mb(19); + up->leap_status = mb(19); - if (up->polled <= 0) - return 0; + 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) { + /* 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]); + printf("TSIP_decode: Not Tracking Sats : %s\n", + *Tracking_Status[st]); #endif - refclock_report(peer, CEVNT_BADTIME); - up->polled = -1; - return 0; - break; - } + 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 - pp->leap = LEAP_DELSECOND; - } - else if (up->leap_status) - pp->leap = LEAP_NOWARNING; + if (up->leap_status & PALISADE_LEAP_PENDING) { + if (up->leap_status & PALISADE_UTC_TIME) + pp->leap = LEAP_ADDSECOND; + else + pp->leap = LEAP_DELSECOND; + } + else if (up->leap_status) + pp->leap = LEAP_NOWARNING; - else { /* UTC flag is not set: - * Receiver may have been reset, and lost - * its UTC almanac data */ - pp->leap = LEAP_NOTINSYNC; + else { /* UTC flag is not set: + * Receiver may have been reset, and lost + * its UTC almanac data */ + pp->leap = LEAP_NOTINSYNC; #ifdef DEBUG - printf("TSIP_decode: UTC Almanac unavailable: %d\n", - mb(19)); + printf("TSIP_decode: UTC Almanac unavailable: %d\n", + mb(19)); #endif - refclock_report(peer, CEVNT_BADTIME); - up->polled = -1; - return 0; - } + refclock_report(peer, CEVNT_BADTIME); + up->polled = -1; + return 0; + } - pp->nsec = (long) (getdbl((u_char *) &mb(3)) * 1000000000); + pp->nsec = (long) (getdbl((u_char *) &mb(3)) + * 1000000000); - if ((pp->day = day_of_year(&mb(14))) < 0) - break; - pp->year = getint((u_char *) &mb(16)); - pp->hour = mb(11); - pp->minute = mb(12); - pp->second = mb(13); + if ((pp->day = day_of_year(&mb(14))) < 0) + break; + pp->year = getint((u_char *) &mb(16)); + pp->hour = mb(11); + pp->minute = mb(12); + pp->second = mb(13); #ifdef DEBUG - if (debug > 1) -printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%06ld %02d/%02d/%04d UTC %02x %s\n", - up->unit, mb(0) & 0xff, event, pp->hour, pp->minute, - pp->second, pp->nsec, mb(15), mb(14), pp->year, - mb(19), *Tracking_Status[st]); + if (debug > 1) + printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%06ld %02d/%02d/%04d UTC %02x %s\n", + up->unit, mb(0) & 0xff, event, pp->hour, pp->minute, + pp->second, pp->nsec, mb(15), mb(14), pp->year, + mb(19), *Tracking_Status[st]); #endif - return 1; - break; + return 1; + break; - case PACKET_8FAC: - if (up->polled <= 0) - return 0; + case PACKET_8FAC: + if (up->polled <= 0) + return 0; - if (up->rpt_cnt != LENCODE_8FAC)/* check length */ - break; + if (up->rpt_cnt != LENCODE_8FAC)/* check length */ + break; #ifdef DEBUG -if (debug > 1) { - double lat, lon, alt; - lat = getdbl((u_char *) &mb(36)) * R2D; - lon = getdbl((u_char *) &mb(44)) * R2D; - alt = getdbl((u_char *) &mb(52)); - - 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\n", up->unit); - } + if (debug > 1) { + double lat, lon, alt; + lat = getdbl((u_char *) &mb(36)) * R2D; + lon = getdbl((u_char *) &mb(44)) * R2D; + alt = getdbl((u_char *) &mb(52)); + + 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\n", up->unit); + } #endif - if (getint((u_char *) &mb(10)) & 0x80) - pp->leap = LEAP_ADDSECOND; /* we ASSUME addsecond */ - else - pp->leap = LEAP_NOWARNING; + if (getint((u_char *) &mb(10)) & 0x80) + pp->leap = LEAP_ADDSECOND; /* we ASSUME addsecond */ + else + pp->leap = LEAP_NOWARNING; #ifdef DEBUG - if (debug > 1) - printf("TSIP_decode: unit %d: 0x%02x leap %d\n", - up->unit, mb(0) & 0xff, pp->leap); - if (debug > 1) { - printf("Receiver MODE: 0x%02X\n", (u_char)mb(1)); - if (mb(1) == 0x00) - printf(" AUTOMATIC\n"); - if (mb(1) == 0x01) - printf(" SINGLE SATELLITE\n"); - if (mb(1) == 0x03) - printf(" HORIZONTAL(2D)\n"); - if (mb(1) == 0x04) - printf(" FULL POSITION(3D)\n"); - if (mb(1) == 0x05) - printf(" DGPR REFERENCE\n"); - if (mb(1) == 0x06) - printf(" CLOCK HOLD(2D)\n"); - if (mb(1) == 0x07) - printf(" OVERDETERMINED CLOCK\n"); - - printf("\n** Disciplining MODE 0x%02X:\n", (u_char)mb(2)); - if (mb(2) == 0x00) - printf(" NORMAL\n"); - if (mb(2) == 0x01) - printf(" POWER-UP\n"); - if (mb(2) == 0x02) - printf(" AUTO HOLDOVER\n"); - if (mb(2) == 0x03) - printf(" MANUAL HOLDOVER\n"); - if (mb(2) == 0x04) - printf(" RECOVERY\n"); - if (mb(2) == 0x06) - printf(" DISCIPLINING DISABLED\n"); - } + if (debug > 1) + printf("TSIP_decode: unit %d: 0x%02x leap %d\n", + up->unit, mb(0) & 0xff, pp->leap); + if (debug > 1) { + printf("Receiver MODE: 0x%02X\n", (u_char)mb(1)); + if (mb(1) == 0x00) + printf(" AUTOMATIC\n"); + if (mb(1) == 0x01) + printf(" SINGLE SATELLITE\n"); + if (mb(1) == 0x03) + printf(" HORIZONTAL(2D)\n"); + if (mb(1) == 0x04) + printf(" FULL POSITION(3D)\n"); + if (mb(1) == 0x05) + printf(" DGPR REFERENCE\n"); + if (mb(1) == 0x06) + printf(" CLOCK HOLD(2D)\n"); + if (mb(1) == 0x07) + printf(" OVERDETERMINED CLOCK\n"); + + printf("\n** Disciplining MODE 0x%02X:\n", (u_char)mb(2)); + if (mb(2) == 0x00) + printf(" NORMAL\n"); + if (mb(2) == 0x01) + printf(" POWER-UP\n"); + if (mb(2) == 0x02) + printf(" AUTO HOLDOVER\n"); + if (mb(2) == 0x03) + printf(" MANUAL HOLDOVER\n"); + if (mb(2) == 0x04) + printf(" RECOVERY\n"); + if (mb(2) == 0x06) + printf(" DISCIPLINING DISABLED\n"); + } #endif - return 0; - break; + return 0; + break; - case PACKET_8FAB: - /* Thunderbolt Primary Timing Packet */ + case PACKET_8FAB: + /* Thunderbolt Primary Timing Packet */ - if (up->rpt_cnt != LENCODE_8FAB) /* check length */ - break; + if (up->rpt_cnt != LENCODE_8FAB) /* check length */ + break; - if (up->polled <= 0) - return 0; + if (up->polled <= 0) + return 0; - GPS_UTC_Offset = getint((u_char *) &mb(7)); + GPS_UTC_Offset = getint((u_char *) &mb(7)); - if (GPS_UTC_Offset == 0){ /* Check UTC Offset */ + if (GPS_UTC_Offset == 0){ /* Check UTC Offset */ #ifdef DEBUG - printf("TSIP_decode: UTC Offset Unknown\n"); + printf("TSIP_decode: UTC Offset Unknown\n"); #endif - break; - } + break; + } - if ((mb(9) & 0x1d) == 0x0) { - /* if we know the GPS time and the UTC offset, - we expect UTC timing information !!! */ + if ((mb(9) & 0x1d) == 0x0) { + /* if we know the GPS time and the UTC offset, + we expect UTC timing information !!! */ - pp->leap = LEAP_NOTINSYNC; - refclock_report(peer, CEVNT_BADTIME); - up->polled = -1; - return 0; - } + pp->leap = LEAP_NOTINSYNC; + refclock_report(peer, CEVNT_BADTIME); + up->polled = -1; + return 0; + } - pp->nsec = 0; + pp->nsec = 0; #ifdef DEBUG - printf("\nTiming Flags are:\n"); - printf("Timing flag value is: 0x%X\n", mb(9)); - if ((mb(9) & 0x01) != 0) - printf (" Getting UTC time\n"); - else - printf (" Getting GPS time\n"); - if ((mb(9) & 0x02) != 0) - printf (" PPS is from UTC\n"); - else - printf (" PPS is from GPS\n"); - if ((mb(9) & 0x04) != 0) - printf (" Time is not Set\n"); - else - printf (" Time is Set\n"); - if ((mb(9) & 0x08) != 0) - printf(" I dont have UTC info\n"); - else - printf (" I have UTC info\n"); - if ((mb(9) & 0x10) != 0) - printf (" Time is from USER\n\n"); - else - printf (" Time is from GPS\n\n"); + printf("\nTiming Flags are:\n"); + printf("Timing flag value is: 0x%X\n", mb(9)); + if ((mb(9) & 0x01) != 0) + printf (" Getting UTC time\n"); + else + printf (" Getting GPS time\n"); + if ((mb(9) & 0x02) != 0) + printf (" PPS is from UTC\n"); + else + printf (" PPS is from GPS\n"); + if ((mb(9) & 0x04) != 0) + printf (" Time is not Set\n"); + else + printf (" Time is Set\n"); + if ((mb(9) & 0x08) != 0) + printf(" I dont have UTC info\n"); + else + printf (" I have UTC info\n"); + if ((mb(9) & 0x10) != 0) + printf (" Time is from USER\n\n"); + else + printf (" Time is from GPS\n\n"); #endif - if ((pp->day = day_of_year(&mb(13))) < 0) - break; - tow = getlong((u_char *) &mb(1)); + if ((pp->day = day_of_year(&mb(13))) < 0) + break; + tow = getlong((u_char *) &mb(1)); #ifdef DEBUG - if (debug > 1) { - printf("pp->day: %d\n", pp->day); - printf("TOW: %ld\n", tow); - printf("DAY: %d\n", mb(13)); - } + if (debug > 1) { + printf("pp->day: %d\n", pp->day); + printf("TOW: %ld\n", tow); + printf("DAY: %d\n", mb(13)); + } #endif - pp->year = getint((u_char *) &mb(15)); - pp->hour = mb(12); - pp->minute = mb(11); - pp->second = mb(10); + pp->year = getint((u_char *) &mb(15)); + pp->hour = mb(12); + pp->minute = mb(11); + pp->second = mb(10); #ifdef DEBUG - if (debug > 1) -printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%06ld %02d/%02d/%04d ",up->unit, mb(0) & 0xff, event, pp->hour, pp->minute, pp->second, pp->nsec, mb(14), mb(13), pp->year); + if (debug > 1) + printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%06ld %02d/%02d/%04d ",up->unit, mb(0) & 0xff, event, pp->hour, pp->minute, pp->second, pp->nsec, mb(14), mb(13), pp->year); #endif - return 1; - break; + return 1; + break; - default: - /* Ignore Packet */ - return 0; - } /* switch */ + default: + /* Ignore Packet */ + return 0; + } /* switch */ }/* if 8F packets */ else if (up->rpt_buf[0] == (u_char)0x42) { - printf("0x42\n"); - return 0; + printf("0x42\n"); + return 0; } else if (up->rpt_buf[0] == (u_char)0x43) { - printf("0x43\n"); - return 0; + printf("0x43\n"); + return 0; } else if (up->rpt_buf[0] == PACKET_41) { - printf("0x41\n"); - return 0; + printf("0x41\n"); + return 0; } else if (up->rpt_buf[0] == PACKET_6D) { #ifdef DEBUG - int sats; + int sats; - if ((mb(0) & 0x01) && (mb(0) & 0x02)) - printf("2d Fix Dimension\n"); - if (mb(0) & 0x04) - printf("3d Fix Dimension\n"); + if ((mb(0) & 0x01) && (mb(0) & 0x02)) + printf("2d Fix Dimension\n"); + if (mb(0) & 0x04) + printf("3d Fix Dimension\n"); - if (mb(0) & 0x08) - printf("Fix Mode is MANUAL\n"); - else - printf("Fix Mode is AUTO\n"); + if (mb(0) & 0x08) + printf("Fix Mode is MANUAL\n"); + else + printf("Fix Mode is AUTO\n"); - sats = mb(0) & 0xF0; - sats = sats >> 4; - printf("Tracking %d Satellites\n", sats); + sats = mb(0) & 0xF0; + sats = sats >> 4; + printf("Tracking %d Satellites\n", sats); #endif return 0; } /* else if not super packet */ @@ -820,8 +776,8 @@ printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%06ld %02d/%02d/%04d ",up- up->polled = -1; #ifdef DEBUG printf("TSIP_decode: unit %d: bad packet %02x-%02x event %d len %d\n", - up->unit, up->rpt_buf[0] & 0xff, mb(0) & 0xff, - event, up->rpt_cnt); + up->unit, up->rpt_buf[0] & 0xff, mb(0) & 0xff, + event, up->rpt_cnt); #endif return 0; } @@ -832,14 +788,8 @@ printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%06ld %02d/%02d/%04d ",up- static void palisade_receive ( -#ifdef PALISADE - peer - ) - struct peer * peer; -#else /* ANSI */ struct peer * peer ) -#endif { struct palisade_unit *up; struct refclockproc *pp; @@ -853,14 +803,14 @@ palisade_receive ( if (! TSIP_decode(peer)) return; if (up->polled <= 0) - return; /* no poll pending, already received or timeout */ + return; /* no poll pending, already received or timeout */ up->polled = 0; /* Poll reply received */ pp->lencode = 0; /* clear time code */ #ifdef DEBUG if (debug) printf( - "palisade_receive: unit %d: %4d %03d %02d:%02d:%02d.%06ld\n", + "palisade_receive: unit %d: %4d %03d %02d:%02d:%02d.%06ld\n", up->unit, pp->year, pp->day, pp->hour, pp->minute, pp->second, pp->nsec); #endif @@ -872,22 +822,15 @@ palisade_receive ( */ (void) sprintf(pp->a_lastcode,"%4d %03d %02d:%02d:%02d.%06ld", - pp->year,pp->day,pp->hour,pp->minute, pp->second,pp->nsec); + pp->year,pp->day,pp->hour,pp->minute, pp->second,pp->nsec); pp->lencode = 24; -#ifdef PALISADE - pp->lasttime = current_time; -#endif - if (!refclock_process(pp -#ifdef PALISADE - , PALISADE_SAMPLES, PALISADE_SAMPLES * 3 / 5 -#endif - )) { + if (!refclock_process(pp)) { refclock_report(peer, CEVNT_BADTIME); #ifdef DEBUG printf("palisade_receive: unit %d: refclock_process failed!\n", - up->unit); + up->unit); #endif return; } @@ -896,16 +839,11 @@ palisade_receive ( #ifdef DEBUG if (debug) - printf("palisade_receive: unit %d: %s\n", - up->unit, prettydate(&pp->lastrec)); + printf("palisade_receive: unit %d: %s\n", + up->unit, prettydate(&pp->lastrec)); #endif pp->lastref = pp->lastrec; - refclock_receive(peer -#ifdef PALISADE - , &pp->offset, 0, pp->dispersion, - &pp->lastrec, &pp->lastrec, pp->leap -#endif - ); + refclock_receive(peer); } @@ -915,16 +853,9 @@ palisade_receive ( */ static void palisade_poll ( -#ifdef PALISADE - unit, peer - ) - int unit; - struct peer *peer; -#else int unit, struct peer *peer ) -#endif { struct palisade_unit *up; struct refclockproc *pp; @@ -934,19 +865,19 @@ palisade_poll ( pp->polls++; if (up->polled > 0) /* last reply never arrived or error */ - refclock_report(peer, CEVNT_TIMEOUT); + refclock_report(peer, CEVNT_TIMEOUT); up->polled = 2; /* synchronous packet + 1 event */ #ifdef DEBUG if (debug) - printf("palisade_poll: unit %d: polling %s\n", unit, - (pp->sloppyclockflag & CLK_FLAG2) ? - "synchronous packet" : "event"); + printf("palisade_poll: unit %d: polling %s\n", unit, + (pp->sloppyclockflag & CLK_FLAG2) ? + "synchronous packet" : "event"); #endif if (pp->sloppyclockflag & CLK_FLAG2) - return; /* using synchronous packet input */ + return; /* using synchronous packet input */ if(up->type == CLK_PRAECIS) { if(write(peer->procptr->io.fd,"SPSTAT\r\n",8) < 0) @@ -958,11 +889,14 @@ palisade_poll ( } if (HW_poll(pp) < 0) - refclock_report(peer, CEVNT_FAULT); + refclock_report(peer, CEVNT_FAULT); } static void -praecis_parse(struct recvbuf *rbufp, struct peer *peer) +praecis_parse ( + struct recvbuf *rbufp, + struct peer *peer + ) { static char buf[100]; static int p = 0; @@ -988,14 +922,8 @@ praecis_parse(struct recvbuf *rbufp, struct peer *peer) static void palisade_io ( -#ifdef PALISADE - rbufp - ) - struct recvbuf *rbufp; -#else /* ANSI */ struct recvbuf *rbufp ) -#endif { /* * Initialize pointers and read the timecode and timestamp. @@ -1044,19 +972,19 @@ palisade_io ( case TSIP_PARSED_DATA: if (*c == DLE) - up->rpt_status = TSIP_PARSED_DLE_2; + up->rpt_status = TSIP_PARSED_DLE_2; else - mb(up->rpt_cnt++) = *c; + mb(up->rpt_cnt++) = *c; break; case TSIP_PARSED_DLE_2: if (*c == DLE) { up->rpt_status = TSIP_PARSED_DATA; mb(up->rpt_cnt++) = - *c; + *c; } else if (*c == ETX) - up->rpt_status = TSIP_PARSED_FULL; + up->rpt_status = TSIP_PARSED_FULL; else { /* error: start new report packet */ up->rpt_status = TSIP_PARSED_DLE_1; @@ -1068,19 +996,19 @@ palisade_io ( case TSIP_PARSED_EMPTY: default: if ( *c != DLE) - up->rpt_status = TSIP_PARSED_EMPTY; - else - up->rpt_status = TSIP_PARSED_DLE_1; + up->rpt_status = TSIP_PARSED_EMPTY; + else + up->rpt_status = TSIP_PARSED_DLE_1; break; } c++; if (up->rpt_status == TSIP_PARSED_DLE_1) { - up->rpt_cnt = 0; + up->rpt_cnt = 0; if (pp->sloppyclockflag & CLK_FLAG2) /* stamp it */ - get_systime(&pp->lastrec); + get_systime(&pp->lastrec); } else if (up->rpt_status == TSIP_PARSED_EMPTY) up->rpt_cnt = 0; @@ -1103,14 +1031,8 @@ palisade_io ( */ long HW_poll ( -#ifdef PALISADE - pp /* pointer to unit structure */ - ) - struct refclockproc * pp; /* pointer to unit structure */ -#else struct refclockproc * pp /* pointer to unit structure */ ) -#endif { int x; /* state before & after RTS set */ struct palisade_unit *up; @@ -1120,8 +1042,8 @@ HW_poll ( /* read the current status, so we put things back right */ if (ioctl(pp->io.fd, TIOCMGET, &x) < 0) { #ifdef DEBUG - if (debug) - printf("Palisade HW_poll: unit %d: GET %s\n", up->unit, strerror(errno)); + if (debug) + printf("Palisade HW_poll: unit %d: GET %s\n", up->unit, strerror(errno)); #endif msyslog(LOG_ERR, "Palisade(%d) HW_poll: ioctl(fd,GET): %m", up->unit); @@ -1133,8 +1055,8 @@ HW_poll ( /* Edge trigger */ if (ioctl(pp->io.fd, TIOCMSET, &x) < 0) { #ifdef DEBUG - if (debug) - printf("Palisade HW_poll: unit %d: SET \n", up->unit); + if (debug) + printf("Palisade HW_poll: unit %d: SET \n", up->unit); #endif msyslog(LOG_ERR, "Palisade(%d) HW_poll: ioctl(fd, SET, RTS_on): %m", @@ -1149,8 +1071,8 @@ HW_poll ( if (ioctl(pp->io.fd, TIOCMSET, &x) == -1) { #ifdef DEBUG - if (debug) - printf("Palisade HW_poll: unit %d: UNSET \n", up->unit); + if (debug) + printf("Palisade HW_poll: unit %d: UNSET \n", up->unit); #endif msyslog(LOG_ERR, "Palisade(%d) HW_poll: ioctl(fd, UNSET, RTS_off): %m", @@ -1167,14 +1089,8 @@ HW_poll ( */ float getfloat ( -#ifdef PALISADE - bp - ) - u_char *bp; -#else u_char *bp ) -#endif { float sval; #ifdef WORDS_BIGENDIAN @@ -1197,14 +1113,8 @@ getfloat ( */ double getdbl ( -#ifdef PALISADE - bp - ) - u_char *bp; -#else u_char *bp ) -#endif { double dval; #ifdef WORDS_BIGENDIAN @@ -1234,16 +1144,10 @@ getdbl ( */ short getint ( -#ifdef PALISADE - bp - ) - u_char *bp; -#else u_char *bp ) -#endif { -return (short) (bp[1] + (bp[0] << 8)); + return (short) (bp[1] + (bp[0] << 8)); } /* @@ -1251,19 +1155,13 @@ return (short) (bp[1] + (bp[0] << 8)); */ long getlong( -#ifdef PALISADE - bp - ) - u_char *bp; -#else u_char *bp ) -#endif { -return (long) (bp[0] << 24) | - (bp[1] << 16) | - (bp[2] << 8) | - bp[3]; + return (long) (bp[0] << 24) | + (bp[1] << 16) | + (bp[2] << 8) | + bp[3]; } int refclock_palisade_bs;