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

📄 tsip_rpt.c

📁 gps开发专用的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * *************************************************************************
 *
 * Trimble Navigation, Ltd.
 * OEM Products Development Group
 * P.O. Box 3642
 * 645 North Mary Avenue
 * Sunnyvale, California 94088-3642
 *
 * Corporate Headquarter:
 *    Telephone:  (408) 481-8000
 *    Fax:        (408) 481-6005
 *
 * Technical Support Center:
 *    Telephone:  (800) 767-4822	(U.S. and Canada)
 *                (408) 481-6940    (outside U.S. and Canada)
 *    Fax:        (408) 481-6020
 *    BBS:        (408) 481-7800
 *    e-mail:     trimble_support@trimble.com
 *
 * *************************************************************************
 *
 * Vers	Date		   Changes				    Author
 * ----	---------   ----------------------------------------	   ----------
 * 1.40
 * 5a10  18 jul 97   matched 5.10 manual         pvwl
 * *************************************************************************
 *
 * TSIP_RPT.C consists of a primary function rpt_packet() called by main().
 * This function takes a character buffer that has been received as a report
 * from a TSIP device and interprets it.  The character buffer has been
 * assembled using tsip_input_proc() in TSIP_IFC.C.
 *
 * A large case statement directs processing to one of many mid-level
 * functions.  The mid-level functions specific to the current report
 * code passes the report buffer to the appropriate report decoder
 * rpt_0x?? () in TSIP_IFC.C, which outputs the variable values in the
 * report buffer rpt.buf.
 *
 * *************************************************************************
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <conio.h>
#include "tsip_ifc.h"
#include "tsipincl.h"
extern char
	 *st_baud_text_app []
	, *able_text2[]
	, *databit_text_app []
	, *dgps_mode_text2[]
	, *dyn_text2 []
	, *flow_cntrl_text[]
	, *in_out_text[]
	, *parity_text []
	, *port_text []
	, *pos_fix_text[]
	, *protocols_text[]
	, *rcvr_port_text []
	, *req_set_text[]
	, *stopbit_text[]
	, *toggle_text[]
	, *trackmode_text3[];

/* TCHAT uses printf(); TSIPCHAT uses cprintf() */
#ifndef xprintf
#define xprintf printf
#endif

#define TSIP_RPT

#define GOOD_PARSE 0
#define BADID_PARSE 1
#define BADLEN_PARSE 2
short parsed;

/* convert time of week into day-hour-minute-second and print */
static void show_time (float time_of_week)
{
	short	days, hours, minutes;
	float seconds;
	double tow;
	const char
		*dname[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

	if (time_of_week == -1.0) {
		xprintf ("   <No time yet>   ");
		return;
	}
	if (time_of_week < 0.0F) time_of_week += 604800.0F;
	if ((time_of_week >= 604800.0) || (time_of_week < 0.0)) {
		xprintf ("     <Bad time>     ");
		return;
	}
	tow = time_of_week;
	days = (short)(tow / 86400.0);
	hours = (short)fmod(tow / 3600., 24.);
	minutes =  (short) fmod(tow/60., 60.);
	seconds = (float)fmod(tow, 60.);
	xprintf (" %s %02d:%02d:%05.2f   ", dname[days], hours, minutes, seconds);
}

/**/
/* 0x3D */
#define MAX_INPUT_MODE     2
#define MAX_OUTPUT_MODE    6
/**/
/* 0x41 */
static void rpt_GPS_time (TSIPPKT *rpt)
{
	float
		time_of_week, UTC_offset;
	short
		week_num;

	/* unload rptbuf */
	if (rpt_0x41 (rpt, &time_of_week, &UTC_offset, &week_num)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("GPS time:");
	show_time (time_of_week);
	xprintf ("GPS week: %d   UTC offset %.1f", week_num, UTC_offset);

	/* This function will reset PC clock if a request has been previously
	* generated in a 'z' command.  Record of the request is kept by
	* time_set_request in TSIP_UTL.C, set by request_PC_time_set()
	* which is called from the 'z' command handler in TSIP_CMD.C
	* This function is not used in TCHAT; a dummy call is in TCHAT.C
	*/
	GPS_time_to_PC (time_of_week + week_num*604800. - UTC_offset);
}

/* 0x42 */
static void rpt_single_ECEF_position (TSIPPKT *rpt)
{
	float
		ECEF_pos[3], time_of_fix;

	/* unload rptbuf */
	if (rpt_0x42 (rpt, ECEF_pos, &time_of_fix)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("SPos: %15.2f%15.2f%15.2f    ",
		ECEF_pos[0], ECEF_pos[1], ECEF_pos[2]);
	show_time (time_of_fix);
}

/* 0x43 */
static void rpt_single_ECEF_velocity (TSIPPKT *rpt)
{

	float
		ECEF_vel[3], freq_offset, time_of_fix;

	/* unload rptbuf */
	if (rpt_0x43 (rpt, ECEF_vel, &freq_offset, &time_of_fix)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("VelECEF: %11.3f%11.3f%11.3f%12.3f    ",
		ECEF_vel[0], ECEF_vel[1], ECEF_vel[2], freq_offset);
	show_time (time_of_fix);
}

/*  0x45  */
static void rpt_SW_version (TSIPPKT *rpt) {
	unsigned char
		major_nav_version, minor_nav_version,
		nav_day, nav_month, nav_year,
		major_dsp_version, minor_dsp_version,
		dsp_day, dsp_month, dsp_year;

	/* unload rptbuf */
	if (rpt_0x45 (rpt,
		&major_nav_version, &minor_nav_version,
		&nav_day, &nav_month, &nav_year,
		&major_dsp_version, &minor_dsp_version,
		&dsp_day, &dsp_month, &dsp_year)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf (
"FW Versions:  Nav Proc %2d.%02d  %2d/%2d/%2d  Sig Proc %2d.%02d  %2d/%2d/%2d",
		major_nav_version, minor_nav_version, nav_day, nav_month, nav_year,
		major_dsp_version, minor_dsp_version, dsp_day, dsp_month, dsp_year);
}

/* 0x46 */
#define MAX_SC_MESSAGE 13
#define MAX_EC_MESSAGE 6
static void rpt_rcvr_health (TSIPPKT *rpt)
{
	unsigned char
		status_code, error_code;
	short
		i;

	const char
		*sc_text[MAX_SC_MESSAGE] = {
		"Doing position fixes",
		"Don't have GPS time yet",
		"Waiting for almanac collection",
		"DOP too high          ",
		"No satellites available",
		"Only 1 satellite available",
		"Only 2 satellites available",
		"Only 3 satellites available",
		"No satellites usable   ",
		"Only 1 satellite usable",
		"Only 2 satellites usable",
		"Only 3 satellites usable",
		"Chosen satellite unusable"},

		*ec_text[MAX_EC_MESSAGE] = {
		"RAM cleared at power-up",
		"Signal processor error ",
		"Channel 1 Misalignment ",
		"Channel 2 Misalignment ",
		"Antenna line open/short",
		"Excessive Osc Freq Bias"};


	/* unload rptbuf */
	if (rpt_0x46 (rpt, &status_code, &error_code))
	{
		parsed = BADLEN_PARSE;
		return;
	}

	if (status_code > MAX_SC_MESSAGE)
	{
		xprintf ("Unknown status code %d", status_code);
	}
	else
	{
		xprintf ("Health of GPS: %s", sc_text[rpt->buf[0]]);
		for (i = 0; i < MAX_EC_MESSAGE; i++) {
			if (error_code & (1 << i)) {
				show_crlf ();
				xprintf ("               %s", ec_text[i]);
			}
		}
	}
}

/* 0x47 */
static void rpt_SNR_all_SVs (TSIPPKT *rpt)
{
	unsigned char
		nsvs, sv_prn[12];
	short
		isv;
	float
		snr[12];

	/* unload rptbuf */
	if (rpt_0x47 (rpt, &nsvs, sv_prn, snr)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("SNR for satellites: %d", nsvs);
	for (isv = 0; isv < nsvs; isv++) {
		show_crlf ();
		xprintf ("   SV %2d   %6.2f", sv_prn[isv], snr[isv]);
	}
}

/* 0x48 */
static void rpt_GPS_system_message (TSIPPKT *rpt)
{
	unsigned char
		message[23];

	/* unload rptbuf */
	if (rpt_0x48 (rpt, message)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("GPS message: %s", message);
}

/* 0x4A */
static void rpt_single_lla_position (TSIPPKT *rpt) {
	short
		lat_deg, lon_deg;
	float
		lat, lon,
		alt, clock_bias, time_of_fix;
	double lat_min, lon_min;
	unsigned char
		north_south, east_west;

	if (rpt_0x4A (rpt,
		&lat, &lon, &alt, &clock_bias, &time_of_fix)) {
		parsed = BADLEN_PARSE;
		return;
	}

	/* convert from radians to degrees */
	lat *= (float)R2D;
	north_south = 'N';
	if (lat < 0.0) {
		north_south = 'S';
		lat = -lat;
	}
	lat_deg = (short)lat;
	lat_min = (lat - lat_deg) * 60.0;

	lon *= (float)R2D;
	east_west = 'E';
	if (lon < 0.0) {
		east_west = 'W';
		lon = -lon;
	}
	lon_deg = (short)lon;
	lon_min = (lon - lon_deg) * 60.0;

	xprintf ("Position:%4d:%06.3f %c%5d:%06.3f %c%10.2f%12.2f",
		lat_deg, lat_min, north_south,
		lon_deg, lon_min, east_west,
		alt, clock_bias);
	show_time (time_of_fix);
}

/* 0x4A */
static void rpt_ref_alt (TSIPPKT *rpt) {

	float
		alt, dummy;
	unsigned char
		alt_flag;

	if (rpt_0x4A_2 (rpt,
		&alt, &dummy, &alt_flag)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("Reference Alt:   %.1f m;    %s", alt, alt_flag?"ON":"OFF");
}

/* 0x4B */
#define MAX_AS1_MESSAGE 4
#define MAX_MID_MESSAGE 41
static void rpt_rcvr_id_and_status (TSIPPKT *rpt)
{
	const char
		*as1_text[MAX_AS1_MESSAGE] = {
		"Synthesizer fault         ",
		"No RTC Timeset at power-up",
		"A-to-D converter fault    ",
		"Almanac not complete      "} ;

	unsigned char
		machine_id, status_1, status_2;
	short
		imsg;

	/* unload rptbuf */
	if (rpt_0x4B (rpt, &machine_id, &status_1, &status_2)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("Machine/Code ID: %d   Status: %d %d", machine_id,
		status_1, status_2);
	for (imsg = 0; imsg < MAX_AS1_MESSAGE; imsg++) {
		if (status_1 & (1 << imsg)) {
			show_crlf ();
			xprintf ("               %s", as1_text[imsg]);
		}
	}
	if (status_2 & 0x01) {
		xprintf ("        Superpackets supported");
	}
}

/* 0x4D */
static void rpt_oscillator_offset (TSIPPKT *rpt)
{
	float
		osc_offset;

	/* unload rptbuf */
	if (rpt_0x4D (rpt, &osc_offset)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("Oscillator offset: %.2f Hz.", osc_offset);
}

/* 0x4E */
static void rpt_GPS_time_set_response (TSIPPKT *rpt)
{

	unsigned char
		response;

	/* unload rptbuf */
	if (rpt_0x4E (rpt, &response)) {
		parsed = BADLEN_PARSE;
		return;
	}

	switch (response) {
	case 'Y':
		xprintf ("Time set accepted");
		break;

	case 'N':
		xprintf ("Time set rejected or not required");
		break;

	default:
		xprintf ("Time set response error");
	}
}

/**/
/* 0x55 */
static void rpt_io_opt (TSIPPKT *rpt)
{
	unsigned char
		pos_code, vel_code, time_code, aux_code;

	/* unload rptbuf */
	if (rpt_0x55 (rpt,
		&pos_code, &vel_code, &time_code, &aux_code)) {
		parsed = BADLEN_PARSE;
		return;
	}
	/* rptbuf unloaded */

	xprintf ("I/O Options:%2X%2X%2X%2X",
		pos_code, vel_code, time_code, aux_code);

	if (pos_code & 0x01) {
		show_crlf ();
		xprintf ("    ECEF XYZ position output");
	}
	if (pos_code & 0x02) {
		show_crlf ();
		xprintf ("    LLA position output");
	}
	show_crlf ();
	xprintf ((pos_code & 0x04)?
		"    MSL altitude output (Geoid height) ":
		"    WGS-84 altitude output");
	show_crlf ();
	xprintf ((pos_code & 0x08)?
		"    MSL altitude input":"    WGS-84 altitude input");
	show_crlf ();
	xprintf ((pos_code & 0x10)?
		"    Double precision":"    Single precision");
	if (pos_code & 0x20) {
		show_crlf ();
		xprintf ("   All Enabled Superpackets");
	}
	if (vel_code & 0x01) {
		show_crlf ();
		xprintf ("    ECEF XYZ velocity output");
	}
	if (vel_code & 0x02) {
		show_crlf ();
		xprintf ("    ENU velocity output");
	}
	show_crlf ();
	xprintf ((time_code & 0x01)?
		  "    Time tags in UTC":"    Time tags in GPS time");
	if (time_code & 0x02) {
		show_crlf ();
		xprintf ("    Fixes delayed to integer seconds");
	}
	if (time_code & 0x04) {
		show_crlf ();
		xprintf ("    Fixes sent only on request");
	}
	if (time_code & 0x08) {
		show_crlf ();
		xprintf ("    Synchronized measurements");
	}
	if (time_code & 0x10) {
		show_crlf ();
		xprintf ("    Minimize measurement propagation");
	}
	if (aux_code & 0x01) {
		show_crlf ();
		xprintf ("    Raw measurement output");
	}
	if (aux_code & 0x02) {
		show_crlf ();
		xprintf ("    Code-phase smoothed before output");
	}
	if (aux_code & 0x04) {
		show_crlf ();
		xprintf ("    Additional fix status");
	}
	show_crlf ();
	xprintf ("    Signal Strength Output as %s",
		(aux_code & 0x08)? "dBHz" : "AMU");
}

/* 0x56 */
static void rpt_ENU_velocity (TSIPPKT *rpt)
{
	float
		vel_ENU[3], freq_offset, time_of_fix;

	/* unload rptbuf */
	if (rpt_0x56 (rpt, vel_ENU, &freq_offset, &time_of_fix)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("Vel ENU:%11.2f%11.2f%11.2f%12.2f    ",
		vel_ENU[0], vel_ENU[1], vel_ENU[2], freq_offset);
	show_time (time_of_fix);
}

/* 0x57 */
#define MAX_SOURCE_MESSAGE 9
static void rpt_last_fix_info (TSIPPKT *rpt)
{
	unsigned char
		source_code, diag_code;
	short
		week_num;
	float
		time_of_fix;
	const char
		*source_text[MAX_SOURCE_MESSAGE] = {
		"temporary no fix",
		"good current fix",
		"converging fix",
		"",
		"shadow fix",
		"user-supplied coarse fix",
		"user-supplied accurate fix",
		"image fix",
		"no fix available"} ;


	/* unload rptbuf */
	if (rpt_0x57 (rpt, &source_code, &diag_code, &week_num, &time_of_fix)) {
		parsed = BADLEN_PARSE;
		return;
	}

	xprintf ("%s;   diag code: %2Xh", source_text[source_code], diag_code);
	show_crlf ();
	xprintf ("Time of last fix:");
	show_time (time_of_fix);
	show_crlf ();
	xprintf ("Week of last fix: %d", week_num);
}

/* 0x58 */
#define MAX_DAT_MESSAGE 7
static void rpt_GPS_system_data (TSIPPKT *rpt)

⌨️ 快捷键说明

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