FreeBSD/contrib/ntp/ntpd/refclock_ripencc.c
/*
 * ripencc_start - open the GPS devices and initialize data for processing
 */
open the GPS devices and initialize data for processing
open the GPS devices and initialize data for processing
static int
ripencc_start(int unit, struct peer *peer)
{
	register struct ripencc_unit *up;
	struct refclockproc *pp;
	char device[40];
	int fd;
	struct termios tio;
	TSIPPKT spt;
	pp = peer->procptr;
	(void)snprintf(device, sizeof(device), DEVICE, unit);
	fd = refclock_open(device, SPEED232, LDISC_RAW);
	if (fd <= 0) {
		pp->io.fd = -1;
		return (0);
	}
	pp->io.fd = fd;
	if (tcgetattr(fd, &tio) < 0) {
		msyslog(LOG_ERR, "Palisade(%d) tcgetattr(fd, &tio): %m",unit);
		return (0);
	}
	tio.c_cflag |= (PARENB|PARODD);
	tio.c_iflag &= ~ICRNL;
	if (tcsetattr(fd, TCSANOW, &tio) == -1) {
		msyslog(LOG_ERR, "Palisade(%d) tcsetattr(fd, &tio): %m",unit);
		return (0);
	}
	up = emalloc_zero(sizeof(*up));
	pp->io.clock_recv = ripencc_receive;
	pp->io.srcclock = peer;
	pp->io.datalen = 0;
	if (!io_addclock(&pp->io)) {
		pp->io.fd = -1;
		close(fd);
		free(up);
		return (0);
	}
	pp->unitptr = up;
	peer->precision = PRECISION;
	pp->clockdesc = DESCRIPTION;
	memcpy((char *)&pp->refid, REFID, REFID_LEN);
	up->pollcnt = 2;
	up->unit = unit;
	up->leapdelta = 0;
	up->utcflags = 0;
	cmd_0x1F(&spt);			
	ripencc_send(peer, spt);          
	cmd_0x26(&spt);			
	ripencc_send(peer, spt);
	cmd_0x8E42q(&spt);		
	ripencc_send(peer, spt);  
	cmd_0x8E41q(&spt);		
	ripencc_send(peer, spt); 
	cmd_0x35s(&spt, 
		  0x1C, 	
		  0x00, 	
		  0x05, 	
		  0x0a); 	
	ripencc_send(peer, spt);
	cmd_0x3Ds (&spt,
		   0x0B,	
		   0x0B,	
		   0x07,	
		   0x07,	
		   0x01,	
		   0x00);	
	ripencc_send(peer, spt);
	cmd_0x8E4As (&spt,
		     0x01,	
		     0x01,	
		     0x00,	
		     0.,	
		     1e-6 * GPS_C); 	
	ripencc_send(peer,spt);
	cmd_0x8E4Ds(&spt,
		    0x00000000); 
	ripencc_send(peer, spt);
	cmd_0xBBq (&spt,
		   0x00);	
	ripencc_send(peer,spt);
	cmd_0x8E4Aq (&spt);	
	ripencc_send(peer,spt);
	cmd_0x8E4Bq (&spt);	
	ripencc_send(peer,spt);
#ifdef DEBUG_NCC
	if (debug)
		printf("ripencc_start: success\n");
#endif 
	if (time_pps_create(fd, &up->handle) < 0) {
		up->handle = 0;
		msyslog(LOG_ERR, "refclock_ripencc: time_pps_create failed: %m");
		return (1);
	}
	return(ripencc_ppsapi(peer, 0, 0));
}
static int ripencc_start ( int unit , struct peer * peer ) { register struct ripencc_unit * up ; struct refclockproc * pp ; char device [ 40 ] ; int fd ; struct termios tio ; TSIPPKT spt ; pp = peer -> procptr ; ( void ) snprintf ( device , sizeof ( device ) , DEVICE , unit ) ; fd = refclock_open ( device , SPEED232 , LDISC_RAW ) ; if ( fd <= 0 ) { pp -> io . fd = -1 ; return ( 0 ) ; } pp -> io . fd = fd ; if ( tcgetattr ( fd , & tio ) < 0 ) { msyslog ( LOG_ERR , " " , unit ) ; return ( 0 ) ; } tio . c_cflag |= ( PARENB | PARODD ) ; tio . c_iflag &= ~ ICRNL ; if ( tcsetattr ( fd , TCSANOW , & tio ) == -1 ) { msyslog ( LOG_ERR , " " , unit ) ; return ( 0 ) ; } up = emalloc_zero ( sizeof ( * up ) ) ; pp -> io . clock_recv = ripencc_receive ; pp -> io . srcclock = peer ; pp -> io . datalen = 0 ; if ( ! io_addclock ( & pp -> io ) ) { pp -> io . fd = -1 ; close ( fd ) ; free ( up ) ; return ( 0 ) ; } pp -> unitptr = up ; peer -> precision = PRECISION ; pp -> clockdesc = DESCRIPTION ; memcpy ( ( char * ) & pp -> refid , REFID , REFID_LEN ) ; up -> pollcnt = 2 ; up -> unit = unit ; up -> leapdelta = 0 ; up -> utcflags = 0 ; cmd_0x1F ( & spt ) ; ripencc_send ( peer , spt ) ; cmd_0x26 ( & spt ) ; ripencc_send ( peer , spt ) ; cmd_0x8E42q ( & spt ) ; ripencc_send ( peer , spt ) ; cmd_0x8E41q ( & spt ) ; ripencc_send ( peer , spt ) ; cmd_0x35s ( & spt , 0x1C , 0x00 , 0x05 , 0x0a ) ; ripencc_send ( peer , spt ) ; cmd_0x3Ds ( & spt , 0x0B , 0x0B , 0x07 , 0x07 , 0x01 , 0x00 ) ; ripencc_send ( peer , spt ) ; cmd_0x8E4As ( & spt , 0x01 , 0x01 , 0x00 , 0. , 1e-6 * GPS_C ) ; ripencc_send ( peer , spt ) ; cmd_0x8E4Ds ( & spt , 0x00000000 ) ; ripencc_send ( peer , spt ) ; cmd_0xBBq ( & spt , 0x00 ) ; ripencc_send ( peer , spt ) ; cmd_0x8E4Aq ( & spt ) ; ripencc_send ( peer , spt ) ; cmd_0x8E4Bq ( & spt ) ; ripencc_send ( peer , spt ) ; #ifdef DEBUG_NCC if ( debug ) printf ( " \n " ) ; #endif if ( time_pps_create ( fd , & up -> handle ) < 0 ) { up -> handle = 0 ; msyslog ( LOG_ERR , " " ) ; return ( 1 ) ; } return ( ripencc_ppsapi ( peer , 0 , 0 ) ) ; }
ripencc_start - open the GPS devices and initialize data for processing
ripencc_start - open the GPS devices and initialize data for processing
/*
	 * Open serial port
	 */ /* from refclock_palisade.c */ /*
	 * set flags
	 */ /*
	 * Allocate and initialize unit structure
	 */ /*
	 * Initialize miscellaneous variables
	 */ /*
	 * Initialize the Clock
	 */ /* query software versions */ /* query receiver health */ /* query serial numbers */ /* query manuf params */ /* i/o opts */ /* trimble manual page A30 */ /* position */ /* velocity */ /* timing */ /* auxilary */ /* turn off port A */ /* baud_out */ /* baud_inp */ /* char_code */ /* stopbitcode */ /* output_mode */ /* input_mode */ /* set i/o options */ /* PPS on */ /* Timebase UTC */ /* polarity positive */ /* 100 ft. cable XXX make flag */ /* turn of biasuncert. > (1us) */ /* all outomatic packet output off */ /* AutoOutputMask */ /* query primary configuration */ /* query PPS parameters */ /* query PPS params */ /* query survey limit */ /* query survey limit */ /* DEBUG_NCC */ /*
	 * Start the PPSAPI interface if it is there. Default to use
	 * the assert edge and do not enable the kernel hardpps.
	 */