/* * acts_receive - receive data from the serial interface */ static void acts_receive( struct recvbuf *rbufp ) { struct actsunit *up; struct refclockproc *pp; struct peer *peer; char tbuf[sizeof(up->buf)]; char * tptr; int octets; /* * Initialize pointers and read the timecode and timestamp. Note * we are in raw mode and victim of whatever the terminal * interface kicks up; so, we have to reassemble messages from * arbitrary fragments. Capture the timecode at the beginning of * the message and at the '*' and '#' on-time characters. */ peer = rbufp->recv_peer; pp = peer->procptr; up = pp->unitptr; octets = sizeof(up->buf) - (up->bufptr - up->buf); refclock_gtraw(rbufp, tbuf, octets, &pp->lastrec); for (tptr = tbuf; *tptr != '\0'; tptr++) { if (*tptr == LF) { if (up->bufptr == up->buf) { up->tstamp = pp->lastrec; continue; } else { *up->bufptr = '\0'; up->bufptr = up->buf; acts_message(peer, up->buf); } } else if (!iscntrl((unsigned char)*tptr)) { *up->bufptr++ = *tptr; if (*tptr == '*' || *tptr == '#') { up->tstamp = pp->lastrec; if (write(pp->io.fd, tptr, 1) < 0) msyslog(LOG_ERR, "acts: write echo fails %m"); } } } }
/* * acts_receive - receive data from the serial interface */ static void acts_receive ( struct recvbuf *rbufp ) { struct actsunit *up; struct refclockproc *pp; struct peer *peer; char tbuf[BMAX]; char *tptr; /* * Initialize pointers and read the timecode and timestamp. Note * we are in raw mode and victim of whatever the terminal * interface kicks up; so, we have to reassemble messages from * arbitrary fragments. Capture the timecode at the beginning of * the message and at the '*' and '#' on-time characters. */ peer = (struct peer *)rbufp->recv_srcclock; pp = peer->procptr; up = (struct actsunit *)pp->unitptr; pp->lencode = refclock_gtraw(rbufp, tbuf, BMAX - (up->bufptr - pp->a_lastcode), &pp->lastrec); for (tptr = tbuf; *tptr != '\0'; tptr++) { if (*tptr == LF) { if (up->bufptr == pp->a_lastcode) { up->tstamp = pp->lastrec; continue; } else { *up->bufptr = '\0'; acts_message(peer); up->bufptr = pp->a_lastcode; } } else if (!iscntrl((unsigned char)*tptr)) { *up->bufptr++ = *tptr; if (*tptr == '*' || *tptr == '#') { up->tstamp = pp->lastrec; write(pp->io.fd, tptr, 1); } } } }