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

📄 gps.c

📁 u-blox的GPS模块LEA-5x,三本例子为ATMEGA1280对他的操作的程序
💻 C
字号:
#include <string.h>
#include "debug.h"
#include "define.h"

//GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>*hh   
//<1> 当前位置的格林尼治时间,格式为hhmmss   
//<2> 状态, A 为有效位置, V为非有效接收警告,即当前天线视野上方的卫星个数少于3颗
//<3> 纬度, 格式为ddmm.mmmm   
//<4> 标明南北半球, N 为北半球、S为南半球   
//<5> 径度,格式为dddmm.mmmm   
//<6> 标明东西半球,E为东半球、W为西半球   
//<7> 地面上的速度,范围为0.0到999.9   
//<8> 方位角,范围为000.0到 359.9 度   
//<9> 日期, 格式为ddmmyy   
//<10> 地磁变化,从000.0到 180.0 度   
//<11> 地磁变化方向,为E 或 W
/*
$GPRMC,072304.00,A,2231.85460,N,11404.40661,E,0.128,,261008,,,A*7C
$GPVTG,,T,,M,0.128,N,0.238,K,A*21
$GPGGA,072304.00,2231.85460,N,11404.40661,E,1,04,10.41,-25.4,M,-2.2,M,,*65
$GPGSA,A,3,07,20,11,50,,,,,,,,,17.78,10.41,14.42*3C
$GPGSV,3,1,10,04,30,234,,07,17,180,32,08,40,215,,11,34,038,29*7C
$GPGSV,3,2,10,20,44,097,51,27,23,193,21,28,63,341,,32,28,070,*78
$GPGSV,3,3,10,42,51,128,39,50,46,122,45*7C
$GPGLL,2231.85460,N,11404.40661,E,072304.00,A,A*63
*/

//-------------------------------------------------------------
//从长度为DataLen数据指针*data中找出字符串*string
//-------------------------------------------------------------
unsigned char find_string(unsigned char *string,unsigned char *data,unsigned int DataLen)
{
	unsigned int StrLen = strlen(string);
	unsigned int i;
	unsigned int j;
	
	for(i=0;i<DataLen;i++)
	{
		if(string[0]==data[i])
		{
			for(j=1;j<StrLen;j++)
			{
				if(string[j]==data[i+j]){
					
				}else{
					return 0;
				}
			}
			if(j==StrLen) return i+1;//就算是在0位置找到的也返回0,处理时减1
		}
	}
	return 0;
}
//-------------------------------------------------------------
//格林尼治时间
//-------------------------------------------------------------
void Greenwich_time(unsigned char *data)
{	
	debug_str_without_n("Greenwich time	:	");
	debug_uchars_without_n(&data[0],2);
	debug_str_without_n(":");
	debug_uchars_without_n(&data[2],2);
	debug_str_without_n(":");
	debug_uchars_without_n(&data[4],2);
	debug_str("");
}
//-------------------------------------------------------------
//纬度
//-------------------------------------------------------------
void latitude(unsigned char *data)
{
	debug_str_without_n("latitude	:	");
	
	debug_uchars_without_n(&data[11],1);
	debug_str_without_n("  ");
	debug_uchars_without_n(&data[0],10);
	debug_str("");
}
//-------------------------------------------------------------
//径度
//-------------------------------------------------------------
void radian(unsigned char *data)
{
	debug_str_without_n("radian		:	");
	
	debug_uchars_without_n(&data[12],1);
	debug_str_without_n("  ");
	debug_uchars_without_n(&data[0],11);
	debug_str("");
}
//-------------------------------------------------------------
//地面速度
//-------------------------------------------------------------
void speed(unsigned char *data)
{
	unsigned char i=0;
	
	debug_str_without_n("speed		:	");
speed_top:
	if(data[i]!='.'){
		debug_uchars_without_n(&data[i],1);
		i++;
		goto speed_top;
	}
	debug_str("");
}
//-------------------------------------------------------------
unsigned char gps_function(unsigned char *data,unsigned int DataLen)
{
	unsigned int mes_addr=0;
	unsigned char availability_flag_1=0;
	unsigned char availability_flag_2=0;
	
	if(data[0]=='$'){
		//debug_uchars(data,DataLen);
	}
			
	if(data[0]=='$'){//判断接收到的GPS数据头一个数据是否为'$'
		mes_addr = find_string("$GPRMC",data,DataLen);//找出字符串"$GPRMC"所在GPS数据中的位置
		if(mes_addr != 0){//有找到
			mes_addr = mes_addr -1; //注意:减1才是真正的字符串位置
			availability_flag_1 = data[mes_addr + 8];//无效数据标志'V'(这个位置不存在'A')
			availability_flag_2 = data[mes_addr + 17];//无效数据标志'V',有效数据标志'A'
			
			if(availability_flag_2 == 'A'){//有效数据
				//debug_str("gps data effective !");
				//<1> 当前位置的格林尼治时间,格式为hhmmss
				Greenwich_time(&data[mes_addr + 7]);
				//纬度
				latitude(&data[mes_addr + 19]);
				//径度
				radian(&data[mes_addr + 32]);
				//地面速度
				speed(&data[mes_addr + 46]);
				//
				debug_str("");
			}
			else if(availability_flag_2 == 'V'){//无效数据(这个有时间返回)
				//debug_str("gps data invalid !");
				//<1> 当前位置的格林尼治时间,格式为hhmmss
				Greenwich_time(&data[mes_addr + 7]);				
			}
			else if(availability_flag_1 == 'V'){//无效数据
				debug_str("gps data invalid !");
			}
			else{//信息有误或处理出错
				debug_str("gps error !");
			}
		}
	}
	return 1;
}

/*
$GPRMC,,V,,,,,,,,,,N*53

$GPVTG,,,,,,,,,N*30

$GPGGA,,,,,,0,00,99.99,,,,,,*48

$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30

$GPGSV,1,1,02,32,,,38,50,,,46*76

$GPGLL,,,,,,V,N*64


gps error !
*/

/*
$GPRMC,075503.00,V,,,,,,,,,,N*79

$GPVTG,,,,,,,,,N*30

$GPGGA,075503.00,,,,,0,00,99.99,,,,,,*62

$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30

$GPGSV,2,1,06,11,,,34,17,,,39,20,,,36,32,,,36*74

$GPGSV,2,2,06,42,,,38,50,,,46*75

$GPGLL,,,,,075503.00,V,N*4E


gps data invalid !
*/

/*
$GPRMC,075603.00,A,2231.90428,N,11404.37384,E,0.652,325.18,261008,,,A*66
$GPVTG,325.18,T,,M,0.652,N,1.209,K,A*3B
$GPGGA,075603.00,2231.90428,N,11404.37384,E,1,04,3.38,66.2,M,-2.2,M,,*76
$GPGSA,A,2,32,17,20,11,,,,,,,,,3.53,3.38,1.00*0A
$GPGSV,2,1,07,02,03,235,,11,22,045,35,17,42,332,37,20,44,074,37*7C
$GPGSV,2,2,07,32,23,054,39,42,51,128,38,50,46,122,46*43
$GPGLL,2231.90428,N,11404.37384,E,075603.00,A,A*60

gps data effective !
*/

⌨️ 快捷键说明

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