📄 refclock_palisade.c
字号:
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;#ifdef DEBUG printf("TSIP_decode: UTC Almanac unavailable: %d\n", mb(19)); #endif refclock_report(peer, CEVNT_BADTIME); up->polled = -1; return 0; } 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);#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]);#endif return 1; break; default: /* Ignore Packet */ return 0; } /* switch */ }/* if 8F packets */ refclock_report(peer, CEVNT_BADREPLY); 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);#endif return 0;}/* * palisade__receive - receive data from the serial interface */static voidpalisade_receive (#ifdef PALISADE peer ) struct peer * peer;#else /* ANSI */ struct peer * peer )#endif{ struct palisade_unit *up; struct refclockproc *pp; /* * Initialize pointers and read the timecode and timestamp. */ pp = peer->procptr; up = (struct palisade_unit *)pp->unitptr; if (! TSIP_decode(peer)) return; if (up->polled <= 0) 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", up->unit, pp->year, pp->day, pp->hour, pp->minute, pp->second, pp->nsec);#endif /* * Process the sample * Generate timecode: YYYY DoY HH:MM:SS.microsec * report and process */ (void) sprintf(pp->a_lastcode,"%4d %03d %02d:%02d:%02d.%06ld", 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 )) { refclock_report(peer, CEVNT_BADTIME);#ifdef DEBUG printf("palisade_receive: unit %d: refclock_process failed!\n", up->unit);#endif return; } record_clock_stats(&peer->srcadr, pp->a_lastcode); #ifdef DEBUG if (debug) 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 );}/* * palisade_poll - called by the transmit procedure * */static voidpalisade_poll (#ifdef PALISADE unit, peer ) int unit; struct peer *peer;#else int unit, struct peer *peer )#endif{ struct palisade_unit *up; struct refclockproc *pp; pp = peer->procptr; up = (struct palisade_unit *)pp->unitptr; pp->polls++; if (up->polled > 0) /* last reply never arrived or error */ 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");#endif if (pp->sloppyclockflag & CLK_FLAG2) return; /* using synchronous packet input */ if(up->type == CLK_PRAECIS) { if(write(peer->procptr->io.fd,"SPSTAT\r\n",8) < 0) msyslog(LOG_ERR, "Palisade(%d) write: %m:",unit); else { praecis_msg = 1; return; } } if (HW_poll(pp) < 0) refclock_report(peer, CEVNT_FAULT); }static voidpraecis_parse(struct recvbuf *rbufp, struct peer *peer){ static char buf[100]; static int p = 0; struct refclockproc *pp; pp = peer->procptr; memcpy(buf+p,rbufp->recv_space.X_recv_buffer, rbufp->recv_length); p += rbufp->recv_length; if(buf[p-2] == '\r' && buf[p-1] == '\n') { buf[p-2] = '\0'; record_clock_stats(&peer->srcadr, buf); p = 0; praecis_msg = 0; if (HW_poll(pp) < 0) refclock_report(peer, CEVNT_FAULT); }}static voidpalisade_io (#ifdef PALISADE rbufp ) struct recvbuf *rbufp;#else /* ANSI */ struct recvbuf *rbufp )#endif{ /* * Initialize pointers and read the timecode and timestamp. */ struct palisade_unit *up; struct refclockproc *pp; struct peer *peer; char * c, * d; peer = (struct peer *)rbufp->recv_srcclock; pp = peer->procptr; up = (struct palisade_unit *)pp->unitptr; if(up->type == CLK_PRAECIS) { if(praecis_msg) { praecis_parse(rbufp,peer); return; } } c = (char *) &rbufp->recv_space; d = c + rbufp->recv_length; while (c != d) { /* Build time packet */ switch (up->rpt_status) { case TSIP_PARSED_DLE_1: switch (*c) { case 0: case DLE: case ETX: up->rpt_status = TSIP_PARSED_EMPTY; break; default: up->rpt_status = TSIP_PARSED_DATA; /* save packet ID */ up->rpt_buf[0] = *c; break; } break; case TSIP_PARSED_DATA: if (*c == DLE) up->rpt_status = TSIP_PARSED_DLE_2; else 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; } else if (*c == ETX) up->rpt_status = TSIP_PARSED_FULL; else { /* error: start new report packet */ up->rpt_status = TSIP_PARSED_DLE_1; up->rpt_buf[0] = *c; } break; case TSIP_PARSED_FULL: case TSIP_PARSED_EMPTY: default: if ( *c != DLE) 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; if (pp->sloppyclockflag & CLK_FLAG2) /* stamp it */ get_systime(&pp->lastrec); } else if (up->rpt_status == TSIP_PARSED_EMPTY) up->rpt_cnt = 0; else if (up->rpt_cnt > BMAX) up->rpt_status =TSIP_PARSED_EMPTY; if (up->rpt_status == TSIP_PARSED_FULL) palisade_receive(peer); } /* while chars in buffer */}/* * Trigger the Palisade's event input, which is driven off the RTS * * Take a system time stamp to match the GPS time stamp. * */longHW_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; up = (struct palisade_unit *) pp->unitptr; /* 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));#endif msyslog(LOG_ERR, "Palisade(%d) HW_poll: ioctl(fd,GET): %m", up->unit); return -1; } x |= TIOCM_RTS; /* turn on RTS */ /* Edge trigger */ if (ioctl(pp->io.fd, TIOCMSET, &x) < 0) { #ifdef DEBUG 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", up->unit); return -1; } x &= ~TIOCM_RTS; /* turn off RTS */ /* poll timestamp */ get_systime(&pp->lastrec); if (ioctl(pp->io.fd, TIOCMSET, &x) == -1) {#ifdef DEBUG 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", up->unit); return -1; } return 0;}#if 0 /* unused *//* * this 'casts' a character array into a float */floatgetfloat (#ifdef PALISADE bp ) u_char *bp;#else u_char *bp )#endif{ float sval;#ifdef WORDS_BIGENDIAN ((char *) &sval)[0] = *bp++; ((char *) &sval)[1] = *bp++; ((char *) &sval)[2] = *bp++; ((char *) &sval)[3] = *bp++;#else ((char *) &sval)[3] = *bp++; ((char *) &sval)[2] = *bp++; ((char *) &sval)[1] = *bp++; ((char *) &sval)[0] = *bp;#endif /* ! XNTP_BIG_ENDIAN */ return sval;}#endif/* * this 'casts' a character array into a double */doublegetdbl (#ifdef PALISADE bp ) u_char *bp;#else u_char *bp )#endif{ double dval;#ifdef WORDS_BIGENDIAN ((char *) &dval)[0] = *bp++; ((char *) &dval)[1] = *bp++; ((char *) &dval)[2] = *bp++; ((char *) &dval)[3] = *bp++; ((char *) &dval)[4] = *bp++; ((char *) &dval)[5] = *bp++; ((char *) &dval)[6] = *bp++; ((char *) &dval)[7] = *bp;#else ((char *) &dval)[7] = *bp++; ((char *) &dval)[6] = *bp++; ((char *) &dval)[5] = *bp++; ((char *) &dval)[4] = *bp++; ((char *) &dval)[3] = *bp++; ((char *) &dval)[2] = *bp++; ((char *) &dval)[1] = *bp++; ((char *) &dval)[0] = *bp;#endif /* ! XNTP_BIG_ENDIAN */ return dval;}/* * cast a 16 bit character array into a short (16 bit) int */shortgetint (#ifdef PALISADE bp ) u_char *bp;#else u_char *bp )#endif{return (short) (bp[1] + (bp[0] << 8));}#elseint refclock_palisade_bs;#endif /* REFCLOCK */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -