热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

GPRM/GNRMC定位信息的读取与解析(3)

GPRMGNRMC定位信息的读取与解析(3)参考网址:http:www.cnblogs.com88223100pGPRM_GNRMC_Tr

GPRM/GNRMC定位信息的读取与解析(3)






参考网址:http://www.cnblogs.com/88223100/p/GPRM_GNRMC_Transform.html






帧头

UTC时间

状态

纬度

北纬/南纬

经度

东经/西经

速度

$GPRMC

hhmmss.sss

A/V

ddmm.mmmm

N/S

dddmm.mmmm

E/W

 

 

 

 

方位角

UTC日期

磁偏角

磁偏角方向

模式

校验

回车换行

ddmmyy

000 - 180

E/W

A/D/E/N

*hh

CR+LF

 


 

 

 

 

 

格 式&#xff1a; $GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>,<12>*hh
$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A*50
说 明&#xff1a;
字段 0&#xff1a;$GPRMC&#xff0c;语句ID&#xff0c;表明该语句为Recommended Minimum Specific GPS/TRANSIT Data&#xff08;RMC&#xff09;推荐最小定位信息
          字段 1&#xff1a;UTC时间&#xff0c;hhmmss.sss格式
          字段 2&#xff1a;状态&#xff0c;A&#61;定位&#xff0c;V&#61;未定位
          字段 3&#xff1a;纬度ddmm.mmmm&#xff0c;度分格式&#xff08;前导位数不足则补0&#xff09;
          字段 4&#xff1a;纬度N&#xff08;北纬&#xff09;或S&#xff08;南纬&#xff09;
          字段 5&#xff1a;经度dddmm.mmmm&#xff0c;度分格式&#xff08;前导位数不足则补0&#xff09;
          字段 6&#xff1a;经度E&#xff08;东经&#xff09;或W&#xff08;西经&#xff09;
          字段 7&#xff1a;速度&#xff0c;节&#xff0c;Knots&#xff08;一节也是1.852千米&#xff0f;小时&#xff09;
          字段 8&#xff1a;方位角&#xff0c;度&#xff08;二维方向指向&#xff0c;相当于二维罗盘&#xff09;
          字段 9&#xff1a;UTC日期&#xff0c;DDMMYY格式
          字段10&#xff1a;磁偏角&#xff0c;&#xff08;000 - 180&#xff09;度&#xff08;前导位数不足则补0&#xff09;
          字段11&#xff1a;磁偏角方向&#xff0c;E&#61;东&#xff0c;W&#61;西
          字段12&#xff1a;模式&#xff0c;A&#61;自动&#xff0c;D&#61;差分&#xff0c;E&#61;估测&#xff0c;N&#61;数据无效&#xff08;3.0协议内容&#xff09;
          字段13&#xff1a;校验值

///

/// GPS信息/// public class GPSInfo{public string Longitude;//经度public string Latitude; //纬度public string Speed; //速度public string GPSStatus;//GPS状态 A&#61;数据有效&#xff1b;V&#61;数据无效public string GPSTime;//GPS时间public string GPSHeading;//航向
}/// /// GPS/BD定位信息解析/// public static class GPSAnalysisClass{/// /// 打开串口/// /// SerialPort/// PortName/// BaudRate/// public static bool OpenSerialPort(SerialPort _SerialPort, string _PortName, int _BaudRate){bool Ret &#61; false;try{_SerialPort.Close();_SerialPort.PortName &#61; _PortName;_SerialPort.BaudRate &#61; _BaudRate;_SerialPort.NewLine &#61; Environment.NewLine;_SerialPort.Open();if (_SerialPort.IsOpen)Ret &#61; true;}catch (Exception ex){Console.WriteLine(ex.Message);Ret &#61; false;}return Ret;}/// /// GNRMC解析[北斗]/// /// 原始字符串/// 北斗定位信息public static GPSInfo GNRMCAnalysis(string _RecString){GPSInfo gpsInfo &#61; null;string[] strtemp &#61; _RecString.Split(&#39;\n&#39;);for (int i &#61; 0; i ){string[] strtemp1 &#61; strtemp[i].Split(&#39;,&#39;);if (strtemp1.Length >&#61; 12){if (strtemp1[0] &#61;&#61; "$GNRMC"){gpsInfo &#61; new GPSInfo();gpsInfo.GPSStatus &#61; strtemp1[2];gpsInfo.GPSHeading &#61; strtemp1[8];gpsInfo.Speed &#61; strtemp1[7] &#61;&#61; "" ? "" : Convert.ToDouble(Convert.ToDouble(strtemp1[7]) * 1.852).ToString("0.0");gpsInfo.Latitude &#61; strtemp1[3] &#61;&#61; "" ? "" : GPSTransforming(strtemp1[3]).ToString("0.000000");gpsInfo.Longitude &#61; strtemp1[5] &#61;&#61; "" ? "" : GPSTransforming(strtemp1[5]).ToString("0.000000");gpsInfo.GPSTime &#61; strtemp1[9] &#61;&#61; "" ? "" : "20" &#43; strtemp1[9].Substring(4, 2) &#43; "-" &#43; strtemp1[9].Substring(2, 2) &#43; "-" &#43; strtemp1[9].Substring(0, 2) &#43; " " &#43; strtemp1[1].Substring(0, 2) &#43; ":" &#43; strtemp1[1].Substring(2, 2) &#43; ":" &#43; strtemp1[1].Substring(4, 2);}}}return gpsInfo;}/// /// GPRM字符串解析[GPS]/// /// 原始字符串/// GPS定位信息public static GPSInfo GPRMCAnalysis(string _RecString){GPSInfo gpsInfo &#61; null;if (!string.IsNullOrEmpty(_RecString)){_RecString &#61; _RecString.Contains("\r") ? _RecString.Substring(0, _RecString.IndexOf("\r")) : _RecString;string[] seg &#61; _RecString.Split(&#39;,&#39;);if (seg.Length >&#61; 12){gpsInfo &#61; new GPSInfo();gpsInfo.GPSStatus &#61; seg[2];//状态gpsInfo.GPSHeading &#61; seg[8];//角度gpsInfo.Speed &#61; seg[7] &#61;&#61; "" ? "" : (Convert.ToDouble(seg[7]) * 1.852).ToString("0.0");//速度gpsInfo.Latitude &#61; seg[4] &#61;&#61; "" ? "" : GPSTransforming(seg[3]).ToString("0.000000");gpsInfo.Longitude &#61; seg[6] &#61;&#61; "" ? "" : GPSTransforming(seg[5]).ToString("0.000000"); ;gpsInfo.GPSTime &#61; seg[9] &#61;&#61; "" ? "" : string.Format("20{0}-{1}-{2} {3}:{4}:{5}", seg[9].Substring(4), seg[9].Substring(2, 2), seg[9].Substring(0, 2), seg[1].Substring(0, 2), seg[1].Substring(2, 2), seg[1].Substring(4));}}return gpsInfo;}/// /// 降度分秒格式经纬度转换为小数经纬度/// /// 度分秒经纬度/// 小数经纬度private static double GPSTransforming(string _Value){double Ret &#61; 0.0;string[] TempStr &#61; _Value.Split(&#39;.&#39;);string x &#61; TempStr[0].Substring(0, TempStr[0].Length - 2);string y &#61; TempStr[0].Substring(TempStr[0].Length - 2, 2);string z &#61; TempStr[1].Substring(0, 4);Ret &#61; Convert.ToDouble(x) &#43; Convert.ToDouble(y) / 60 &#43; Convert.ToDouble(z) / 600000;return Ret;}}


推荐阅读
author-avatar
BLUE1352_126
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有