FreeBSD/contrib/ntp/ntpd/refclock_hopfser.c
/*
 * hopfserial_start - open the devices and initialize data for processing
 */
open the devices and initialize data for processing
open the devices and initialize data for processing
static int
hopfserial_start (
	int unit,
	struct peer *peer
	)
{
	register struct hopfclock_unit *up;
	struct refclockproc *pp;
	int fd;
	char gpsdev[20];
	snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
	fd = refclock_open(gpsdev, SPEED232, LDISC_CLK);
	if (fd <= 0) {
#ifdef DEBUG
		printf("hopfSerialClock(%d) start: open %s failed\n", unit, gpsdev);
#endif
		return 0;
	}
	msyslog(LOG_NOTICE, "hopfSerialClock(%d) fd: %d dev: %s", unit, fd,
		gpsdev);
	up = emalloc_zero(sizeof(*up));
	pp = peer->procptr;
	pp->unitptr = up;
	pp->io.clock_recv = hopfserial_receive;
	pp->io.srcclock = peer;
	pp->io.datalen = 0;
	pp->io.fd = fd;
	if (!io_addclock(&pp->io)) {
#ifdef DEBUG
		printf("hopfSerialClock(%d) io_addclock\n", unit);
#endif
		close(fd);
		pp->io.fd = -1;
		free(up);
		pp->unitptr = NULL;
		return (0);
	}
	pp->clockdesc = DESCRIPTION;
	peer->precision = PRECISION;
	memcpy((char *)&pp->refid, REFID, 4);
	up->leap_status = 0;
	up->unit = (short) unit;
	return (1);
}
static int hopfserial_start ( int unit , struct peer * peer ) { register struct hopfclock_unit * up ; struct refclockproc * pp ; int fd ; char gpsdev [ 20 ] ; snprintf ( gpsdev , sizeof ( gpsdev ) , DEVICE , unit ) ; fd = refclock_open ( gpsdev , SPEED232 , LDISC_CLK ) ; if ( fd <= 0 ) { #ifdef DEBUG printf ( " \n " , unit , gpsdev ) ; #endif return 0 ; } msyslog ( LOG_NOTICE , " " , unit , fd , gpsdev ) ; up = emalloc_zero ( sizeof ( * up ) ) ; pp = peer -> procptr ; pp -> unitptr = up ; pp -> io . clock_recv = hopfserial_receive ; pp -> io . srcclock = peer ; pp -> io . datalen = 0 ; pp -> io . fd = fd ; if ( ! io_addclock ( & pp -> io ) ) { #ifdef DEBUG printf ( " \n " , unit ) ; #endif close ( fd ) ; pp -> io . fd = -1 ; free ( up ) ; pp -> unitptr = NULL ; return ( 0 ) ; } pp -> clockdesc = DESCRIPTION ; peer -> precision = PRECISION ; memcpy ( ( char * ) & pp -> refid , REFID , 4 ) ; up -> leap_status = 0 ; up -> unit = ( short ) unit ; return ( 1 ) ; }
hopfserial_start - open the devices and initialize data for processing
hopfserial_start - open the devices and initialize data for processing
/* LDISC_STD, LDISC_RAW
	 * Open serial port. Use CLK line discipline, if available.
	 */ /*
	 * Allocate and initialize unit structure
	 */ /*
	 * Initialize miscellaneous variables
	 */