OSDN Git Service

3f09b39cca69cb27e89d4f248fcc9c74da4da0d3
[yubeshi/yubeshi.git] / Yubeshi / Ubx / NavSol.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.Ubx\r
13 {\r
14     public class NavSol : Packet\r
15     {\r
16         #region constructors\r
17 \r
18         public NavSol(byte[] sentence, int length)\r
19             : base(sentence, length)\r
20         {\r
21             ID = MessageID.NavSol;\r
22             \r
23             uint tow = BitConverter.ToUInt32(sentence, 6 + 0);\r
24             int ftow = BitConverter.ToInt32(sentence, 6 + 4);\r
25             TimeOfWeek = tow * 1e-3m + ftow * 1e-9m;\r
26             Week = BitConverter.ToInt16(sentence, 6 + 8);\r
27             PositionFixType = (GpsFixType)sentence[6 + 10];\r
28             FixFlags = (FixStatusFlag)sentence[6 + 11];\r
29             int x = BitConverter.ToInt32(sentence, 6 + 12);\r
30             int y = BitConverter.ToInt32(sentence, 6 + 16);\r
31             int z = BitConverter.ToInt32(sentence, 6 + 20);\r
32             uint acc = BitConverter.ToUInt32(sentence, 6 + 24);\r
33             Position = new EcefCoordinate(x, y, z, acc);\r
34             int vx = BitConverter.ToInt32(sentence, 6 + 28);\r
35             int vy = BitConverter.ToInt32(sentence, 6 + 32);\r
36             int vz = BitConverter.ToInt32(sentence, 6 + 36);\r
37             uint vAcc = BitConverter.ToUInt32(sentence, 6 + 40);\r
38             Velocity = new EcefVelocity(vx, vy, vz, vAcc);\r
39         }\r
40 \r
41         #endregion\r
42 \r
43         #region properties\r
44 \r
45         public decimal TimeOfWeek\r
46         {\r
47             get;\r
48             private set;\r
49         }\r
50 \r
51         public int Week\r
52         {\r
53             get;\r
54             private set;\r
55         }\r
56 \r
57         public GpsFixType PositionFixType\r
58         {\r
59             get;\r
60             private set;\r
61         }\r
62 \r
63         public FixStatusFlag FixFlags\r
64         {\r
65             get;\r
66             private set;\r
67         }\r
68 \r
69         public EcefCoordinate Position\r
70         {\r
71             get;\r
72             private set;\r
73         }\r
74 \r
75         public EcefVelocity Velocity\r
76         {\r
77             get;\r
78             private set;\r
79         }\r
80 \r
81         public int SVsUsed\r
82         {\r
83             get;\r
84             private set;\r
85         }\r
86         #endregion\r
87 \r
88         #region public methods\r
89 \r
90         public static bool TryParse(byte[] sentence, out UnknownPacket packet)\r
91         {\r
92             return TryParse(sentence, out packet, MessageID.NavSol, 52, Build);\r
93         }\r
94 \r
95         #endregion\r
96 \r
97         #region private methods\r
98 \r
99         private static Packet Build(byte[] sentence, int length)\r
100         {\r
101             return new NavSol(sentence, length);\r
102         }\r
103 \r
104         #endregion\r
105     }\r
106 }\r