`
isiqi
  • 浏览: 16041576 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

GPS NMEA0183协议解析

阅读更多

相关文章:实战Windows Embedded CE 6.0—GPS

这几天忙里偷闲集中把GPS NMEA0183协议好好研究了一下,不仅整理了一份相对较完整的协议文本,并且编写了一个相对较完善的GPS协议解析程序。

<shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="图片_x0020_1" style="VISIBILITY: visible; WIDTH: 182.25pt; HEIGHT: 262.5pt; mso-wrap-style: square" o:spid="_x0000_i1025" type="#_x0000_t75" alt="GPS0806201.jpg"><imagedata src="file:///C:%5CDOCUME~1%5C%E5%8F%B6%E5%B8%86%5CLOCALS~1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_image001.jpg" o:title="GPS0806201"></imagedata></shape>

上图是我所说的测试程序,已经可以获得定位数据及相关卫星信息。

NMEA 0183是美国国家海洋电子协会(National Marine Electronics Association )为海用电子设备制定的标准格式。目前业已成了GPS导航设备统一的RTCM标准协议。

序号

命令

说明

最大帧长

1

$GPGGA

全球定位数据

72

2

$GPGSA

卫星PRN数据

65

3

$GPGSV

卫星状态信息

210

4

$GPRMC

运输定位数据

70

5

$GPVTG

地面速度信息

34

6

$GPGLL

大地坐标信息

7

$GPZDA

UTC时间和日期

注:发送次序$PZDA$GPGGA$GPGLL$GPVTG$GPGSA$GPGSV*3$GPRMC

协议帧总说明:

该协议采用ASCII 码,其串行通信默认参数为:波特率=4800bps,数据位=8bit,开始位=1bit,停止位=1bit,无奇偶校验。

帧格式形如:$aaccc,ddd,ddd,…,ddd*hh<CR><LF>

1“$”--帧命令起始位

2aaccc--地址域,前两位为识别符,后三位为语句名

3ddd…ddd—数据

4、“*校验和前缀

5hh—校验和,$*之间所有字符代码的校验和(各字节做异或运算,得到校验和后,再转换16进制格式的ASCII字符。)

6<CR><LF>--帧结束,回车和换行

其中$GPRMC比较重要,下面略加介绍。

1$GPRMC(Recommended Minimum Specific GPS/TRANSIT Data)

帧头

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

式:$GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>,<12>*hh<CR><LF>

$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A*50

明:

字段 0$GPRMC,语句ID,表明该语句为Recommended Minimum Specific GPS/TRANSIT DataRMC)推荐最小定位信息

字段 1UTC时间,hhmmss.sss格式

字段 2:状态,A=定位,V=未定位

字段 3:纬度ddmm.mmmm,度分格式(前导位数不足则补0

字段 4:纬度N(北纬)或S(南纬)

字段 5:经度dddmm.mmmm,度分格式(前导位数不足则补0

字段 6:经度E(东经)或W(西经)

字段 7:速度,节,Knots一节也是1.852千米/小时)

字段 8:方位角,度(二维方向指向,相当于二维罗盘)

字段 9UTC日期,DDMMYY格式

字段10:磁偏角,(000 - 180)度(前导位数不足则补0

字段11:磁偏角方向,E=东,W=西

字段12:模式,A=自动,D=差分,E=估测,N=数据无效(3.0协议内容)

字段13:校验值

对应的程序代码如下:

     //运输定位数据
            private bool GPRMC_Parse(string data)
            {
                string[] source = Split(data, "$GPRMC");
                if (source != null && source.Length >= 12)
                {
                    //状态
                    this.AnchorState = source[2];
                    //纬度
                    if (source[4].Length > 0 && source[3].Length > 2)
                    {
                        this.Latitude = string.Format("{0}{1},{2}", source[4], source[3].Substring(0, 2), source[3].Substring(2));
                    }
                    else
                    {
                        this.Latitude = "";
                    }
                    //经度
                    if (source[6].Length > 0 && source[5].Length > 3)
                    {
                        this.Longitude = string.Format("{0}{1},{2}", source[6], source[5].Substring(0, 3), source[5].Substring(3));
                    }
                    else
                    {
                        this.Longitude = "";
                    }
                    //速度
                    if (source[7].Length > 0)
                    {
                        this.NSpeed = double.Parse(source[7]);
                    }
                   else
                    {
                        this.NSpeed = 0;
                    }
                    //方位
                    if (source[8].Length > 0)
                    {
                        this.Track = double.Parse(source[8]);
                    }
                    else
                    {

                       this.Track = 0;
                    }
                    //磁偏角和方位
                    if (source[10].Length > 0 && source[11].Length > 0)
                    {
                        this.Magnetic = string.Format("{0} {1}", source[11], source[10]);
                    }
                    else
                    {
                        this.Magnetic = "";
                    }
                    //模式
                    if (source.Length >= 13)
                    {
                        this.WorkMode = source[12];
                    }
                    //时间
                    try
                    {
                        if (source[9].Length == 6 && source[1].Length >= 6)
                        {
                            string dtString = string.Format("{0}-{1}-{2} {3}:{4}:{5}",
                                source[9].Substring(4),
                                source[9].Substring(2, 2),
                                source[9].Substring(0, 2),
                                source[1].Substring(0, 2),
                                source[1].Substring(2, 2),
                                source[1].Substring(4));
                            this.UTCDateTime = DateTime.Parse(dtString);
                        }
                    }
                    catch { return false; }
                    return true;
                }
                return false;
            }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics