⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 refclock_oncore.c

📁 网络时间协议NTP 源码 版本v4.2.0b 该源码用于linux平台下
💻 C
📖 第 1 页 / 共 5 页
字号:
 */static voidoncore_msg_any(	struct instance *instance,	u_char *buf,	size_t len,	int idx	){	int i;	const char *fmt = oncore_messages[idx].fmt;	const char *p;#ifdef HAVE_GETCLOCK	struct timespec ts;#endif	struct timeval tv;	if (debug > 3) {#ifdef HAVE_GETCLOCK		(void) getclock(TIMEOFDAY, &ts);		tv.tv_sec = ts.tv_sec;		tv.tv_usec = ts.tv_nsec / 1000;#else		GETTIMEOFDAY(&tv, 0);#endif		printf("ONCORE[%d]: %ld.%06ld\n", instance->unit, (long) tv.tv_sec, (long) tv.tv_usec);		if (!*fmt) {			printf(">>@@%c%c ", buf[2], buf[3]);			for(i=2; i < len && i < 2400 ; i++)				printf("%02x", buf[i]);			printf("\n");			return;		} else {			printf("##");			for (p = fmt; *p; p++) {				putchar(*p);				putchar('_');			}			printf("\n%c%c", buf[2], buf[3]);			i = 4;			for (p = fmt; *p; p++) {				printf("%02x", buf[i++]);			}			printf("\n");		}	}}/* Latitude, Longitude, Height */static voidoncore_msg_Adef(	struct instance *instance,	u_char *buf,	size_t len	){}/* Mask Angle */static voidoncore_msg_Ag(	struct instance *instance,	u_char *buf,	size_t len	){		char  Msg[160], *cp;		cp = "set to";		if (instance->o_state == ONCORE_RUN)			cp = "is";		instance->Ag = buf[4];		sprintf(Msg, "Satellite mask angle %s %d degrees", cp, (int) instance->Ag);		record_clock_stats(&(instance->peer->srcadr), Msg);}/* * get Position hold position */static voidoncore_msg_As(	struct instance *instance,	u_char *buf,	size_t len	){	instance->ss_lat  = buf_w32(&buf[4]);	instance->ss_long = buf_w32(&buf[8]);	instance->ss_ht   = buf_w32(&buf[12]);	/* Print out Position */	oncore_print_posn(instance);}/* * Try to use Oncore UT+ Auto Survey Feature *	If its not there (VP), set flag to do it ourselves. */static voidoncore_msg_At(	struct instance *instance,	u_char *buf,	size_t len	){	char	*cp;	instance->saw_At = 1;	if (instance->site_survey == ONCORE_SS_TESTING) {		if (buf[4] == 2) {			record_clock_stats(&(instance->peer->srcadr),					"Initiating hardware 3D site survey");			cp = "SSstate = ONCORE_SS_HW";			record_clock_stats(&(instance->peer->srcadr), cp);			instance->site_survey = ONCORE_SS_HW;		}	}}/* * get PPS Offset * Nb. @@Ay is not supported for early UT (no plus) model */static voidoncore_msg_Ay(	struct instance *instance,	u_char *buf,	size_t len	){	char Msg[120];	if (instance->saw_Ay)		return;	instance->saw_Ay = 1;	instance->offset = buf_w32(&buf[4]);	sprintf(Msg, "PPS Offset is set to %ld ns", instance->offset);	record_clock_stats(&(instance->peer->srcadr), Msg);}/* * get Cable Delay */static voidoncore_msg_Az(	struct instance *instance,	u_char *buf,	size_t len	){	char Msg[120];	if (instance->saw_Az)		return;	instance->saw_Az = 1;	instance->delay = buf_w32(&buf[4]);	sprintf(Msg, "Cable delay is set to %ld ns", instance->delay);	record_clock_stats(&(instance->peer->srcadr), Msg);}/* Ba, Ea and Ha come here, these contain Position */static voidoncore_msg_BaEaHa(	struct instance *instance,	u_char *buf,	size_t len	){	const char	*cp;	char		Msg[160];	int		mode;	/* OK, we are close to the RUN state now.	 * But we have a few more items to initialize first.	 *	 * At the beginning of this routine there are several 'timers'.	 * We enter this routine 1/sec, and since the upper levels of NTP have usurped	 * the use of timers, we use the 1/sec entry to do things that	 * we would normally do with timers...	 */	if (instance->o_state == ONCORE_CHECK_CHAN) {	/* here while checking for the # chan */		if (buf[2] == 'B') {		/* 6chan */			if (instance->chan_ck < 6) instance->chan_ck = 6;		} else if (buf[2] == 'E') {	/* 8chan */			if (instance->chan_ck < 8) instance->chan_ck = 8;		} else if (buf[2] == 'H') {	/* 12chan */			if (instance->chan_ck < 12) instance->chan_ck = 12;		}		if (instance->count3++ < 5)			return;		instance->count3 = 0;		if (instance->chan_in != -1)	/* set in Input */			instance->chan = instance->chan_in;		else				/* set from test */			instance->chan = instance->chan_ck;		sprintf(Msg, "Input   says chan = %d", instance->chan_in);		record_clock_stats(&(instance->peer->srcadr), Msg);		sprintf(Msg, "Model # says chan = %d", instance->chan_id);		record_clock_stats(&(instance->peer->srcadr), Msg);		sprintf(Msg, "Testing says chan = %d", instance->chan_ck);		record_clock_stats(&(instance->peer->srcadr), Msg);		sprintf(Msg, "Using        chan = %d", instance->chan);		record_clock_stats(&(instance->peer->srcadr), Msg);		instance->o_state = ONCORE_HAVE_CHAN;		cp = "state = ONCORE_HAVE_CHAN";		record_clock_stats(&(instance->peer->srcadr), cp);		instance->timeout = 4;		oncore_sendmsg(instance->ttyfd, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));		return;	}	if (instance->o_state != ONCORE_ALMANAC && instance->o_state != ONCORE_RUN)		return;	/* PAUSE 5sec - make sure results are stable, before using position */	if (instance->count) {		if (instance->count++ < 5)			return;		instance->count = 0;	}	memcpy(instance->BEHa, buf, (size_t) (len+3));	/* Ba, Ea or Ha */	/* check the antenna (did it get unplugged) and almanac (is it ready) for changes. */	oncore_check_almanac(instance);	oncore_check_antenna(instance);	/* If we are in Almanac mode, waiting for Almanac, we can't do anything till we have it */	/* When we have an almanac, we will start the Bn/En/@@Hn messages */	if (instance->o_state == ONCORE_ALMANAC)		if (oncore_wait_almanac(instance))			return;	/* do some things once when we get this far in BaEaHa */	if (instance->once) {		instance->once = 0;		instance->count2 = 1;		/* Have we seen an @@At (position hold) command response */		/* if not, message out */		if (instance->chan != 12 && !instance->saw_At) {			cp = "Not Good, no @@At command (no Position Hold), must be a GT/GT+";			record_clock_stats(&(instance->peer->srcadr), cp);			oncore_sendmsg(instance->ttyfd, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));		}		/* have an Almanac, can start the SiteSurvey		 * (actually only need to get past the almanac_load where we diddle with At		 *  command,- we can't change it after we start the HW_SS below		 */		mode = instance->init_type;		switch (mode) {		case 0: /* NO initialization, don't change anything */		case 1: /* Use given Position */		case 3:			instance->site_survey = ONCORE_SS_DONE;			cp = "SSstate = ONCORE_SS_DONE";			record_clock_stats(&(instance->peer->srcadr), cp);			break;		case 2:		case 4: /* Site Survey */			cp = "SSstate = ONCORE_SS_TESTING";			record_clock_stats(&(instance->peer->srcadr), cp);			instance->site_survey = ONCORE_SS_TESTING;			instance->count1 = 1;			if (instance->chan == 12)				oncore_sendmsg(instance->ttyfd, oncore_cmd_Gd3,  sizeof(oncore_cmd_Gd3));  /* M12+T */			else				oncore_sendmsg(instance->ttyfd, oncore_cmd_At2,  sizeof(oncore_cmd_At2));  /* not GT, arg not VP */			break;		}		/* Read back PPS Offset for Output */		/* Nb. This will fail silently for early UT (no plus) and M12 models */		oncore_sendmsg(instance->ttyfd, oncore_cmd_Ayx,  sizeof(oncore_cmd_Ayx));		/* Read back Cable Delay for Output */		oncore_sendmsg(instance->ttyfd, oncore_cmd_Azx,  sizeof(oncore_cmd_Azx));		/* Read back Satellite Mask Angle for Output */		oncore_sendmsg(instance->ttyfd, oncore_cmd_Agx,  sizeof(oncore_cmd_Agx));	}	/* Unfortunately, the Gd3 command returns '3' for the M12 v1.3 firmware where it is	 * out-of-range and it should return 0-2. (v1.3 can't do a HW Site Survey)	 * We must do the Gd3, and then wait a cycle or two for things to settle,	 * then check Ha[130]&0x10 to see if a SS is in progress.	 * We will set SW if HW has not been set after an appropriate delay.	 */	if (instance->site_survey == ONCORE_SS_TESTING) {		if (instance->chan == 12) {			if (instance->count1) {				if (instance->count1++ > 5 || instance->BEHa[130]&0x10) {					instance->count1 = 0;					if (instance->BEHa[130]&0x10) {						record_clock_stats(&(instance->peer->srcadr),								"Initiating hardware 3D site survey");						record_clock_stats(&(instance->peer->srcadr), "SSstate = ONCORE_SS_HW");						instance->site_survey = ONCORE_SS_HW;					} else {						record_clock_stats(&(instance->peer->srcadr), "SSstate = ONCORE_SS_SW");						instance->site_survey = ONCORE_SS_SW;					}				}			}		} else {			if (instance->count1) {				if (instance->count1++ > 5) {					instance->count1 = 0;					/*					 * For instance->site_survey to still be ONCORE_SS_TESTING, then after a 5sec					 * wait after the @@At2/@@Gd3 command we have not changed the state to					 * ONCORE_SS_HW.  If the Hardware is capable of doing a Site Survey, then					 * the variable would have been changed by now.					 * There are three possibilities:					 * 6/8chan					 *   (a) We did not get a response to the @@At0 or @@At2 commands,					 *	   and it must be a GT/GT+/SL with no position hold mode.					 *	   We will have to do it ourselves.					 *   (b) We saw the @@At0, @@At2 commands, but @@At2 failed,					 *	   must be a VP or older UT which doesn't have Site Survey mode.					 *	   We will have to do it ourselves.					 * 12chan					 *   (c) We saw the @@Gd command, and saw H[13]*0x10					 *	   We will have to do it ourselves (done above)					 */					sprintf(Msg, "Initiating software 3D site survey (%d samples)",						POS_HOLD_AVERAGE);					record_clock_stats(&(instance->peer->srcadr), Msg);					record_clock_stats(&(instance->peer->srcadr), "SSstate = ONCORE_SS_SW");					instance->site_survey = ONCORE_SS_SW;					instance->ss_lat = instance->ss_long = instance->ss_ht = 0;					if (instance->chan == 12)						oncore_sendmsg(instance->ttyfd, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* disable */					else {						oncore_sendmsg(instance->ttyfd, oncore_cmd_At0, sizeof(oncore_cmd_At0)); /* disable */						oncore_sendmsg(instance->ttyfd, oncore_cmd_Av0, sizeof(oncore_cmd_Av0)); /* disable */					}				}			}		}	}	/* check the mode we are in 0/2/3D */	if (instance->chan == 6) {		if (instance->BEHa[64]&0x8)			instance->mode = MODE_0D;		else if (instance->BEHa[64]&0x10)			instance->mode = MODE_2D;		else if (instance->BEHa[64]&0x20)			instance->mode = MODE_3D;	} else if (instance->chan == 8) {		if (instance->BEHa[72]&0x8)			instance->mode = MODE_0D;		else if (instance->BEHa[72]&0x10)			instance->mode = MODE_2D;		else if (instance->BEHa[72]&0x20)			instance->mode = MODE_3D;	} else if (instance->chan == 12) {		int bits;		bits = (instance->BEHa[129]>>5) & 0x7;	/* actually Ha */		if (bits == 0x

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -