4 * This software is distributed under a zlib-style license.
\r
5 * See license.txt for more information.
\r
9 using System.Collections.Generic;
\r
12 namespace Yubeshi.Nmea
\r
15 /// Latitude and Longitude, with Time of Position Fix and Status
\r
17 public class GpGll : Packet
\r
19 #region type definitions
\r
31 private static Dictionary<string, Mode> modes;
\r
32 private static readonly byte[] header;
\r
33 private const int elementNum = -1; // 6 or 7
\r
38 #region constructors
\r
42 header = Encoding.ASCII.GetBytes("$GPGLL,");
\r
44 modes = new Dictionary<string, Mode>();
\r
45 modes["N"] = Mode.None;
\r
46 modes["A"] = Mode.Autonomous;
\r
47 modes["D"] = Mode.Differential;
\r
48 modes["E"] = Mode.DeadReckoning;
\r
55 public GpGll(byte[] sentence)
\r
56 : this(sentence, GetElements(sentence, elementNum))
\r
60 private GpGll(byte[] sentence, Elements elements)
\r
62 string[] v = elements.Values;
\r
63 if (v.Length < 6 || v.Length > 7)
\r
65 throw new ArgumentException();
\r
67 Position = new GeodeticCoordinate(
\r
68 Degree.FromNmeaFormat(v[0], v[1]),
\r
69 Degree.FromNmeaFormat(v[2], v[3]));
\r
70 CurrentTime = ParseTime(v[4]);
\r
71 DataStatus = ParseStatus(v[5]);
\r
72 PositioningMode = (v.Length == 7) ?
\r
73 GetPositioningMode(v[6]): Mode.Unknown;
\r
74 CheckSum = elements.CheckSum;
\r
81 public GeodeticCoordinate Position
\r
87 public TimeSpan CurrentTime
\r
93 public Status DataStatus
\r
99 public Mode PositioningMode
\r
107 #region public method
\r
109 public static bool TryParse(byte[] sentence, out UnknownPacket packet)
\r
111 return TryParse(sentence, out packet, header, elementNum, Build);
\r
116 #region private method
\r
118 private static Packet Build(byte[] sentence, Elements elements)
\r
120 return new GpGll(sentence, elements);
\r
123 private Mode GetPositioningMode(string mode)
\r
126 if (modes.TryGetValue(mode, out m))
\r
130 return Mode.Unknown;
\r