OSDN Git Service

Ubxパケットの部分的実装
[yubeshi/yubeshi.git] / Yubeshi / Nmea / GpGga.cs
1 /*\r
2  *      Yubeshi GPS Parser\r
3  *\r
4  *      This software is distributed under a zlib-style license.\r
5  *      See license.txt for more information.\r
6  */\r
7 \r
8 using System;\r
9 using System.Collections.Generic;\r
10 using System.Text;\r
11 \r
12 namespace Yubeshi.Nmea\r
13 {\r
14     /// <summary>\r
15     ///     Global Positioning System Fix Data\r
16     /// </summary>\r
17         public class GpGga : Packet\r
18     {\r
19         #region type definitions\r
20         public enum FixQualityClass\r
21         {\r
22             Invalid = 0,\r
23             Gps = 1,\r
24             Dgps = 2,\r
25             Pps = 3,\r
26             Rtk = 4,\r
27             FloatRtk = 5,\r
28             Estimated = 6,\r
29         }\r
30         #endregion\r
31         #region fields\r
32 \r
33         private static readonly byte[] header;\r
34         private const int elementNum = 14;\r
35 \r
36         #endregion\r
37 \r
38         #region constructors\r
39 \r
40         static GpGga()\r
41         {\r
42             header = Encoding.ASCII.GetBytes("$GPGGA,");\r
43         }\r
44 \r
45                 public GpGga()\r
46                 {\r
47                 }\r
48 \r
49                 public GpGga(byte[] sentence)\r
50             : this(sentence, GetElements(sentence, elementNum))\r
51                 {\r
52         }\r
53 \r
54         private GpGga(byte[] sentence, Elements elements)\r
55         {\r
56             Raw = new byte[elements.PacketLength];\r
57             Array.Copy(sentence, Raw, elements.PacketLength);\r
58             string[] v = elements.Values;\r
59             TimeOfFix = ParseTime(v[0]);\r
60             Position = new Coordinate(v[1], v[2], v[3], v[4]);\r
61             FixQuality = (FixQualityClass)Int32.Parse(v[5]);\r
62             TrackedSatellites = Int32.Parse(v[6]);\r
63             Dilution = Decimal.Parse(v[7]);\r
64             MslAltitude = GetLength(v[8], v[9]);\r
65             GeoidSeparation = GetLength(v[10], v[11]);\r
66             \r
67             CheckSum = elements.CheckSum;\r
68         }\r
69 \r
70         #endregion\r
71 \r
72         #region properties\r
73 \r
74         public TimeSpan TimeOfFix\r
75         {\r
76             get;\r
77             private set;\r
78         }\r
79         \r
80         public Coordinate Position\r
81         {\r
82             get;\r
83             private set;\r
84         }\r
85 \r
86         public FixQualityClass FixQuality\r
87         {\r
88             get;\r
89             private set;\r
90         }\r
91 \r
92         public int TrackedSatellites\r
93         {\r
94             get;\r
95             private set;\r
96         }\r
97 \r
98         public decimal Dilution\r
99         {\r
100             get;\r
101             private set;\r
102         }\r
103 \r
104         public decimal MslAltitude\r
105         {\r
106             get;\r
107             private set;\r
108         }\r
109 \r
110         public decimal GeoidSeparation\r
111         {\r
112             get;\r
113             private set;\r
114         }\r
115 \r
116         public int StationID\r
117         {\r
118             get;\r
119             private set;\r
120         }\r
121         #endregion\r
122 \r
123 \r
124         public static bool TryParse(byte[] sentence, out Packet packet)\r
125         {\r
126             return TryParse(sentence, out packet, header, elementNum, Build);\r
127         }\r
128 \r
129         private static Packet Build(byte[] sentence, Elements elements)\r
130         {\r
131             return new GpGga(sentence, elements);\r
132         }\r
133 \r
134         }\r
135 }