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

📄 garmin.c

📁 这是经典的卫星编程应用程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	} //!done

	p=e;
	done =0;
	while(!done) {
		if(*in==0)  done=1;
		*p++ = *in++;
	} //!done

	p=f;
	done =0;
	while(!done) {
		if(*in==0)  done=1;
		*p++ = *in++;
	} //!done

} // SplitOutD108Data

/* -------------------------------------------------------------------------- */
PROCX void readD108(BYTE *aa)
{
	unsigned char *p;
	float altitude;
	INT i;
	D108_Wpt=(D108_Wpt_Type *)aa;
/*
 * Date/Time  Not unused in D108, so set it to system time
 */
	settime_record(0);
	record.class = D108_Wpt->wpt_class;
 	record.la = toDegrees(D108_Wpt->posn.lat);
 	record.lo = toDegrees(D108_Wpt->posn.lon);
 	set_ns();
 	record.icon_smbl=D108_Wpt->smbl;
 	record.class = D108_Wpt->wpt_class;
 	for(i=0;i<18;i++) record.subclass[i]=D108_Wpt->subclass[i];
	record.altitude=D108_Wpt->alt;

	SplitOutD108Data(D108_Wpt->ident,record.ident,
	                                 record.comment,
									 record.facility,
									 record.city,
	                                 record.addr,
									 record.cross_road);
} // readD108

/* -------------------------------------------------------------------------- */
PROCX void readD150(BYTE *aa)
{
	D150_Wpt=(D150_Wpt_Type *)aa;
	strncpy(record.ident, D150_Wpt->ident, 6);
	strncpy(record.cc, D150_Wpt->cc,2);
	record.class = D150_Wpt->class;
	record.la = D150_Wpt->posn.lat;
	record.lo = D150_Wpt->posn.lon;
	set_ns();
	record.alt = D150_Wpt->alt;
	strncpy(record.city, D150_Wpt->city, 24);
	strncpy(record.state, D150_Wpt->state, 2);
	strncpy(record.name, D150_Wpt->name, 30);
	strncpy(record.comment, D150_Wpt->cmnt, 40);
} // readD150

/* -------------------------------------------------------------------------- */
PROCX void doWaypoint(INT wpt)
{
	extern struct PREFS gPrefs;

	BYTE *pp;
	char buf[100];

	set_record_icon();
	pp = (BYTE *)(&SerialMessage[3]); 
	datatype=wpt;

	switch(wpt) {
		case 100:
		case 101:
		case 102:
		case 103:
		case 104:
		case 107:
		case 151:
		case 152:
		case 154:
		case 155:
		case 400:
		case 403:
				readD100(pp, wpt);
				break;

		case 105:
				D105orD106=1;
				readD105(pp);
				break;

		case 106:
				D105orD106=1;
				readD106(pp);
				break;

		case 108:
				readD108(pp);
				break;

		case 150:
		case 450:
				readD150(pp);
				break;
		default:
				fprintf(stderr,"Unknown Waypoint Protocol in doWaypoint -- aborting\n");
				byebye(7);
	} // switch(wpt)
//
// convert symbols if ID is of a 12/II+ gps
//
	if(Ggps == G12XL ) {
				record.icon_smbl  = convert_from_12xl(record.icon_smbl);
	}
	sprintf(Text,"%c;%d;%s;%s",'W',datatype,record.ident,record.comment);
	trim(Text);
	strcpy(buf,Text);
	if(in_route) {
		strcpy(buf,Text);
		push_route();
		strcpy(Text,buf);
	}
	push_waypoint();
	D105orD106=0;
} // doWaypoint

/* -------------------------------------------------------------------------- */
PROCX void doProxWaypoint()
{
	proximity=1;

	doWaypoint(ProxDataRecord);			// decode most of waypoint

	datatype=ProxDataRecord;
	switch(ProxDataRecord) {
// 101, 102 and 152 records contain proximity data no special handling is
//  necessary
		case 101:
		case 102:
		case 152:  break;

		case 400:  D400_Prx_Wpt = (D400_Prx_Wpt_Type *) D100_Wpt;
				   record.ProxDist = D400_Prx_Wpt->dst;
				   break;
		case 403:  D403_Prx_Wpt = (D403_Prx_Wpt_Type *) D103_Wpt; 
				   record.ProxDist = D403_Prx_Wpt->dst;
				   break;
		case 450:  D450_Prx_Wpt = (D450_Prx_Wpt_Type *) D150_Wpt; 
				   record.ProxDist = D450_Prx_Wpt->dst;
				   break;

		default: fprintf(stderr,"Unknown Proximity Protocol %d\n",ProxDataRecord); 
	}

	sprintf(Text,"%c;%d;%s;%s",'P',datatype,record.ident,record.comment);
	strupr(Text);
	push_proximity();
} // doProxWaypoint

/* -------------------------------------------------------------------------- */
PROCX void doTrack()
{
	if(TrackDataRecord!=300) {
		fprintf(stderr,"Unknown TrackDataRecord protocol: %d\n",TrackDataRecord);
	}

	datatype=TrackDataRecord;
	D300_Trk_Point = (D300_Trk_Point_Type *)&SerialMessage[3];

	settime_record((time_t)D300_Trk_Point->time);

	if (D300_Trk_Point->new_trk) {	// New track
		record.type='N';
	}
	else record.type='T';
	record.la = toDegrees(D300_Trk_Point->posn.lat);
	record.lo = toDegrees(D300_Trk_Point->posn.lon);
	sprintf(Text,"%c;%d;;",record.type,datatype);
	push_track();
} // doTrack

/* ----------------------------------------------------------- */
PROCX void doSTrack()
{

	if(firsttrackpoint) send_num_points(tracks,"tracks");
	firsttrackpoint=0;

	D300_Trk_Point = (D300_Trk_Point_Type *)&message[2];

	D300_Trk_Point->posn.lat = toSemiCircles(record.la);
	D300_Trk_Point->posn.lon = toSemiCircles(record.lo);

	message[0] = Pid_Trk_Data;
	message[1] = sizeof(D300_Trk_Point_Type);	/* number of message bytes to follow */

	D300_Trk_Point->time = dt2secs((short)gPrefs.offset);

	if(newTrack==255) newTrack=1;
	D300_Trk_Point->new_trk = newTrack;		/* new track flag */
	newTrack = 0;
	SendGarminMessage(message, 15,"Track data");
	getGarminMessage(1);	/* make sure GPS receiver responded */
} /* doSTrack */

/* -------------------------------------------------------------------------- */
PROCX void doTime(void)
{
	dtime = (D600_Date_Time_Type *)&SerialMessage[3];

	record.year=dtime->year;
	record.monthn=dtime->month;
	record.dayofmonth=dtime->day;
	record.ht=dtime->hour;
	record.mt=dtime->minute;
	record.st=dtime->second;
	sprintf(record.datetime, "%s %s %02d %02d:%02d:%02d %04d", 
		days[dow(record.dayofmonth,record.monthn,record.year)],
		months[record.monthn], 
		record.dayofmonth, record.ht, record.mt, record.st,
		record.year);
} // doTime

/* -------------------------------------------------------------------------- */
PROCX void doSTime(void)
{
	time_t t;
	struct tm *gmt;

	dtime=(D600_Date_Time_Type *)&message[2];
	message[0]=Pid_Date_Time_Data;
	message[1]=sizeof(D600_Date_Time_Type); // 8 bytes
	t=time(NULL);
	gmt=gmtime(&t);
	dtime->month=gmt->tm_mon+1;
	dtime->day=gmt->tm_mday;
	dtime->year=gmt->tm_year+1900;
	dtime->hour=gmt->tm_hour;
	dtime->minute=gmt->tm_min;
	dtime->second=gmt->tm_sec;

	SendGarminMessage(message, 10, "Sending UTC date/time");
	getGarminMessage(1);	/* make sure GPS receiver responded */
} // doSTime()

/* -------------------------------------------------------------------------- */
PROCX void doGPSPos(void)
{
	D700_Position_Type *a;
	LONGdouble Degree=Pi/180.0;

	a=(D700_Position_Type *)&SerialMessage[3];
	record.la = (double)((LONGdouble)a->lat/Degree);
	record.lo = (double)((LONGdouble)a->lon/Degree); 
} /* doGPSPos */

//	Cmnd_Start_Pvt_Data = 49, // 0x31	start transmitting PVT
//	Cmnd_Stop_Pvt_Data	= 50  // 0x32	stop transmitting PVT data
//	Pid_Pvt_Data		= 51, // 0x33   PVT record ID
/* -------------------------------------------------------------------------- */
//
// Tell GPS to send PVT data
//
PROCX void getPVT(void)
{
	SendGarminMessage(PVTon,4,"Start sending PVT Data");	// ask for PVT data
	getGarminMessage(1); 									// get & parse the ack
} // getPVT(void)

/* -------------------------------------------------------------------------- */
//typedef struct
//{
//	float alt; /* altitude above WGS 84 ellipsoid (meters) */
//	float epe; /* estimated position error, 2 sigma (meters) */
//	float eph; /* epe, but horizontal only (meters) */
//	float epv; /* epe, but vertical only (meters) */
//	INT fix; /* type of position fix */
//	double tow; /* time of week (seconds) */
//	Radian_Type posn; /* latitude and longitude (radians) */
//	float east; /* velocity east (meters/second) */
//	float north; /* velocity north (meters/second) */
//	float up; /* velocity up (meters/second) */
//	float msl_hght; /* height of WGS 84 ellipsoid above MSL (meters) */
//	INT leap_scnds; /* difference between GPS and UTC (seconds) */
//	long wn_days; /* week number days */
//} D800_Pvt_Data_Type;


PROCX void doPVT(void)
{
	D800_Pvt_Data_Type *p;
	double la,lo;

	p = (D800_Pvt_Data_Type *)&SerialMessage[3];

	la=p->posn.lat*RADtoDEG;
	lo=p->posn.lon*RADtoDEG;

	printf("%f,%f,%f,%f,%d,%lf,%lf,%lf,%f,%f,%f,%f,%d,%ld\n",
	p->alt,p->epe,p->eph,p->epv,p->fix,p->tow,la,lo,p->east,p->north,p->up,p->msl_hght,
	p->leap_scnds,p->wn_days);
} // doPVT

/* -------------------------------------------------------------------------- */
//
// Tell GPS to stop sending PVT data
//
PROCX void stopPVT(void)
{
	SendGarminMessage(PVToff,4,"Stop sending PVT Data");	// ask for PVT data
	getGarminMessage(1);		 						// get & parse the ack
} // stopPVT()

/* -------------------------------------------------------------------------- */
PROCX void getGPSTime(void)
{
	SendGarminMessage(GPStime,4,"Send GPS Time");	/* ask for time */
	getGarminMessage(1); 		/* get ack	*/
	getGarminMessage(1);		/* get time	*/
} /* getGPSTime */

/* -------------------------------------------------------------------------- */
PROCX void getGPSPosition(void)
{
	SendGarminMessage(GPSPos,4,"Send GPS Position");	// ask for position
	getGarminMessage(1); 									// get & parse ack
	getGarminMessage(1);									// get & parse Position
} /* getGPSPosition */

/* -------------------------------------------------------------------------- */
PROCX void getGPSVolts(void)
{
	SendGarminMessage(VoltsM,4,"Send Voltages");	// ask for volts
	getGarminMessage(1); 						// get & parse ack
	getGarminMessage(1);						// get & parse volts
	printf("Int: %5.2lf,  Ext: %5.2lf\n",InternalVolts,ExternalVolts);
} /* getGPSVolts */

/* -------------------------------------------------------------------------- */
PROCX void doRouteName()
{
	char ix[MAX_LENGTH];

	if(in_route==1) {
		sprintf(ix,"E  %02d\n",route_number);
		push_record(ix,0);
	}
	in_route=1;
	switch(RouteHdrType) {
		case 200:
				D200=*(SerialMessage+3);
				route_number=D200;
				strcpy(route_comment,"None");
				break;
		case 201:
				D201=(D201_Rte_Hdr_Type *)&SerialMessage[3];
				route_number=D201->nmbr;
				strncpy(route_comment,D201->cmnt,20);
				break;
		case 202:
				D202=(D202_Rte_Hdr_Type *)&SerialMessage[3];
				strcpy(route_comment,D202->rte_ident);
				null_newline(route_comment);
				break;
	} // switch(RouteHdrType)

	if(RouteHdrType==202) route_number++;
	sprintf(rtn,"%02d",route_number);
	sprintf(ix,"R  %02d %s",route_number,route_comment);
	push_record(ix,0);
} /* doRouteName */

/* -------------------------------------------------------------------------- */
/* Returns a result code--zero if GPS receiver did not respond */
/*
 *  When sending route data the sequence is:
 *
 *  1.  Send 'Route/ID' record.  Read the responding ACK/NAK
 *  2.  Send 'Number of records to follow' record, Read ACK/NAK
 *  3.  Send each waypoint in the route as a route waypoint record and
 *       read each ACK/NAK
 *  4.  Send 'Route end of database record'.  Read ACK/NAK
 * 
 */
PROCX void doSRouteHdr()
{
/*
 * send number of route waypoint records to send +1 for the route name
 */
	*((short*)(bgnxfr+2)) = routeXpts[route_number]+1;
	SendGarminMessage(bgnxfr, 4, "bgnxfr, Route");
	getGarminMessage(1);	/* make sure GPS receiver responded */

⌨️ 快捷键说明

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