$GPRMC解析

$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 Data(RMC)推薦最小定位信息
          字段 1:UTC時間,hhmmss.sss格式
          字段 2:狀態,A=定位,V=未定位
          字段 3:緯度ddmm.mmmm,度分格式(前導位數不足則補0)
          字段 4:緯度N(北緯)或S(南緯)
          字段 5:經度dddmm.mmmm,度分格式(前導位數不足則補0)
          字段 6:經度E(東經)或W(西經)
          字段 7:速度,節,Knots(一節也是1.852千米/小時)
          字段 8:方位角,度(二維方向指向,相當於二維羅盤)
          字段 9:UTC日期,DDMMYY格式
          字段10:磁偏角,(000 - 180)度(前導位數不足則補0)
          字段11:磁偏角方向,E=東,W=西
          字段12:模式,A=自動,D=差分,E=估測,N=數據無效(3.0協議內容)
          字段13:校驗值
對應的程序代碼如下:

 

view plaincopy to clipboardprint?
01.//運輸定位數據  
02.       private bool GPRMC_Parse(string data)  
03.       {  
04.           string[] source = Split(data, "$GPRMC");  
05.           if (source != null && source.Length >= 12)  
06.           {  
07.               //狀態  
08.               this.AnchorState = source[2];  
09.               //緯度  
10.               if (source[4].Length > 0 && source[3].Length > 2)  
11.               {  
12.                   this.Latitude = string.Format("{0}{1},{2}", source[4], source[3].Substring(0, 2), source[3].Substring(2));  
13.               }  
14.               else 
15.               {  
16.                   this.Latitude = "";  
17.               }  
18.               //經度  
19.               if (source[6].Length > 0 && source[5].Length > 3)  
20.               {  
21.                   this.Longitude = string.Format("{0}{1},{2}", source[6], source[5].Substring(0, 3), source[5].Substring(3));  
22.               }  
23.               else 
24.               {  
25.                   this.Longitude = "";  
26.               }  
27.               //速度  
28.               if (source[7].Length > 0)  
29.               {  
30.                   this.NSpeed = double.Parse(source[7]);  
31.               }  
32.              else 
33.               {  
34.                   this.NSpeed = 0;  
35.               }  
36.               //方位  
37.               if (source[8].Length > 0)  
38.               {  
39.                   this.Track = double.Parse(source[8]);  
40.               }  
41.               else 
42.               {  
43. 
44.                  this.Track = 0;  
45.               }  
46.               //磁偏角和方位  
47.               if (source[10].Length > 0 && source[11].Length > 0)  
48.               {  
49.                   this.Magnetic = string.Format("{0} {1}", source[11], source[10]);  
50.               }  
51.               else 
52.               {  
53.                   this.Magnetic = "";  
54.               }  
55.               //模式  
56.               if (source.Length >= 13)  
57.               {  
58.                   this.WorkMode = source[12];  
59.               }  
60.               //時間  
61.               try 
62.               {  
63.                   if (source[9].Length == 6 && source[1].Length >= 6)  
64.                   {  
65.                       string dtString = string.Format("{0}-{1}-{2} {3}:{4}:{5}",  
66.                           source[9].Substring(4),  
67.                           source[9].Substring(2, 2),  
68.                           source[9].Substring(0, 2),  
69.                           source[1].Substring(0, 2),  
70.                           source[1].Substring(2, 2),  
71.                           source[1].Substring(4));  
72.                       this.UTCDateTime = DateTime.Parse(dtString);  
73.                   }  
74.               }  
75.               catch { return false; }  
76.               return true;  
77.           }  
78.           return false;  
79.       } 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章