加入收藏 | 设为首页 | 会员中心 | 我要投稿 广西网 (https://www.guangxiwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

NMEA-0183之$GPRMC数据处理

发布时间:2021-03-10 15:25:15 所属栏目:大数据 来源:网络整理
导读:NMEA-0183 u?以下为 GPS 芯片串口发出的数据: 201512_15:42:3712,$GPTXT,ANTSTATUS=SHORT*43 201512_15:42:37$GNGGA,074219.000,3021.516740,N,12005.998703,E,1,9,1.09,20.996,M,6.991,*42 201512_15:42:37$GNGLL,A,A*45 201512_15:42:37$GPGSA,3,20,18,25
副标题[/!--empirenews.page--]

NMEA-0183

u?以下为GPS芯片串口发出的数据:

201512_15:42:3712,$GPTXT,ANTSTATUS=SHORT*43
201512_15:42:37$GNGGA,074219.000,3021.516740,N,12005.998703,E,1,9,1.09,20.996,M,6.991,*42
201512_15:42:37$GNGLL,A,A*45
201512_15:42:37$GPGSA,3,20,18,25,10,24,15,22,14,1.38,0.85*07
201512_15:42:37$BDGSA,06,0.85*1A
201512_15:42:37$GPGSV,12,89,182,30,55,320,35,47,038,31,40,107,33*73
201512_15:42:38$GPGSV,2,34,297,29,33,315,32,156,077,31*7F
201512_15:42:38$GPGSV,140,08,227,27,37,193,31*4A
201512_15:42:38$BDGSV,01,75,066,27*58
201512_15:42:38$GNVTG,128.46,T,0.00,K,A*2A
201512_15:42:38$GNRMC,311215,A*7E

?

u?数据接收:

GPRMC格式,数据长度不会超过70;

GPGGA格式,数据长度不会超过72;

??以’$’开始保存,若长度超过74则丢弃并重新接收,否则判断结束符r’’n’;

??首次收到’则向GPS芯片发送模式(GPS/BD/MIX)控制命令字;

??判断GPS_RX[3、4、5]是否为’R、M、C’,是则开始处理;

?

u?数据处理:

??判断锁定位;

??时间:小时要+8,若>24则需-24;

??日期:需修正

static void DateRepair(void)
{
	uint8 day_tmp,mon_tmp,year_tmp;				// 日,月,年暂存
	year_tmp = ((gps_data.date_time[0] >> 4) * 10) + (gps_data.date_time[0] & 0xf);
	mon_tmp = ((gps_data.date_time[1] >> 4) * 10) + (gps_data.date_time[1] & 0xf);
	day_tmp = ((gps_data.date_time[2] >> 4) * 10) + (gps_data.date_time[2] & 0xf);
	day_tmp++;
	//GPSDATA.date[0]++;
	if(mon_tmp == 2)		// 如果是2月份
	{
		if((year_tmp % 4) != 0)
		{	//闰年
			if(day_tmp > 28)
			{	//28天
				day_tmp = 1;
				mon_tmp++;
			}
		}
		else 
		{
			if(day_tmp > 29)
			{	//29天
				day_tmp = 1;
				mon_tmp++;
			}
		}
	} 
	else if((mon_tmp == 4) || (mon_tmp == 6) || (mon_tmp == 9) || (mon_tmp == 11))
	{	//4,6,11月份
		if(day_tmp > 30)
		{
			day_tmp = 1;
			mon_tmp++;
		}
	} 
	else
	{
		if(day_tmp > 31)
		{	//1,5,7,8,12月份
			day_tmp = 1;
			mon_tmp++;
			if(mon_tmp > 12)
			{
				mon_tmp = 1;
				year_tmp++;
			}
		}
	}
	gps_data.date_time[0] = ((year_tmp / 10) << 4) + (year_tmp % 10);		// year
	gps_data.date_time[1] = ((mon_tmp / 10) << 4) + (mon_tmp % 10);			// mon
	gps_data.date_time[2] = ((day_tmp / 10) << 4) + (day_tmp % 10);			// day
}
?

??经纬度

纬度ddmm.mmmm(度分)格式(前面的0也被传输),如3021.5167=120.099786;

经度dddmm.mmmm(度分)格式(前面的0也被传输),如12005.9872=30.358613;

static void longlat_sel(uint8 *pd,uint8 len)
{
	uint8 j,jj,jjj;
	// 先处理纬度
	j = lookup(pd,',len);
	if(j)
	{
		for(jj = 0; jj < 5; jj++)
		{
			if((pd[j + jj] == '.') || (pd[j + jj] == ','))
				break;
		}
		//gps_data.latitude[0] = 0;
		switch(jj)
		{
			case 4:
				gps_data.latitude[0] = ((pd[j] & 0x0f) << 4) + (pd[j + 1] & 0x0f);
				gps_data.latitude[1] = ((pd[j + 2] & 0x0f) << 4) + (pd[j + 3] & 0x0f);
				break;
			case 3:
				gps_data.latitude[0] = pd[j] & 0x0f;
				gps_data.latitude[1] = ((pd[j + 1] & 0x0f) << 4) + (pd[j + 2] & 0x0f);
				break;
			case 2:
				gps_data.latitude[0] = 0;
				gps_data.latitude[1] = ((pd[j] & 0x0f) << 4) + (pd[j + 1] & 0x0f);
				break;
			case 1:
				gps_data.latitude[0] = 0;
				gps_data.latitude[1] = pd[j] & 0x0f;
				break;
			default:
				gps_data.latitude[0] = 0;
				gps_data.latitude[1] = 0;
				break; 
		}
		jjj = lookup(pd,4,len);
		switch(jjj - j - jj - 2)	// 小数点后的位数
		{
			case 6:
			case 5:
			case 4:
				gps_data.latitude[2] = ((pd[j + jj + 1] & 0x0f) << 4) + (pd[j + jj + 2] & 0x0f);
				gps_data.latitude[3] = ((pd[j + jj + 3] & 0x0f) << 4) + (pd[j + jj + 4] & 0x0f);
				break;
			case 3:
				gps_data.latitude[2] = ((pd[j + jj + 1] & 0x0f) << 4) + (pd[j + jj + 2] & 0x0f);
				gps_data.latitude[3] = (pd[j + jj + 3] & 0x0f) << 4;
				break;
			case 2:
				gps_data.latitude[2] = ((pd[j + jj + 1] & 0x0f) << 4) + (pd[j + jj + 2] & 0x0f);
				gps_data.latitude[3] = 0;
				break;
			case 1:
				gps_data.latitude[2] = (pd[j + jj + 1] & 0x0f) << 4;
				gps_data.latitude[3] = 0;
				break;
			default:
				gps_data.latitude[2] = 0;
				gps_data.latitude[3] = 0;
				break; 
		}
	}
	// 再处理经度
	j = lookup(pd,len); 
	if(j)
	{
		for(jj = 0; jj < 5; jj++)
		{
			if((pd[j + jj] == '.') || (pd[j + jj] == ','))
				break;
		}
		switch(jj)
		{
			case 5:
				gps_data.longitude[0] = pd[j] & 0x0f;
				gps_data.longitude[1] = ((pd[j + 1] & 0x0f) << 4) + (pd[j + 2] & 0x0f);
				gps_data.longitude[2] = ((pd[j + 3] & 0x0f) << 4) + (pd[j + 4] & 0x0f);
				break;
			case 4:
				gps_data.longitude[0] = 0;
				gps_data.longitude[1] = ((pd[j] & 0x0f) << 4) + (pd[j + 1] & 0x0f);
				gps_data.longitude[2] = ((pd[j + 2] & 0x0f) << 4) + (pd[j + 3] & 0x0f);
				break;
			case 3:
				gps_data.longitude[0] = 0;
				gps_data.longitude[1] = pd[j] & 0x0f;
				gps_data.longitude[2] = ((pd[j + 1] & 0x0f) << 4) + (pd[j + 2] & 0x0f);
				break;
			case 2:
				gps_data.longitude[0] = 0;
				gps_data.longitude[1] = 0;
				gps_data.longitude[2] = ((pd[j] & 0x0f) << 4) + (pd[j + 1] & 0x0f);
				break;
			case 1:
				gps_data.longitude[0] = 0;
				gps_data.longitude[1] = 0;
				gps_data.longitude[2] = pd[j] & 0x0f;
				break;
			default:
				gps_data.longitude[0] = 0;
				gps_data.longitude[1] = 0;
				gps_data.longitude[2] = 0;
				break; 
		}
		jjj = lookup(pd,len);
		switch(jjj - j - jj - 2)	// 小数点后的位数
		{
			case 6:
			case 5:
			case 4:
				gps_data.longitude[3] = ((pd[j + jj + 1] & 0x0f) << 4) + (pd[j + jj + 2] & 0x0f);
				gps_data.longitude[4] = ((pd[j + jj + 3] & 0x0f) << 4) + (pd[j + jj + 4] & 0x0f);
				break;
			case 3:
				gps_data.longitude[3] = ((pd[j + jj + 1] & 0x0f) << 4) + (pd[j + jj + 2] & 0x0f);
				gps_data.longitude[4] = (pd[j + jj + 3] & 0x0f) << 4;
				break;
			case 2:
				gps_data.longitude[3] = ((pd[j + jj + 1] & 0x0f) << 4) + (pd[j + jj + 2] & 0x0f);
				gps_data.longitude[4] = 0;
				break;
			case 1:
				gps_data.longitude[3] = (pd[j + jj + 1] & 0x0f) << 4;
				gps_data.longitude[4] = 0;
				break;
			default:
				gps_data.longitude[3] = 0;
				gps_data.longitude[4] = 0;
				break;
		}
	}
}

(编辑:广西网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!