\r
public static Degree FromNmeaFormat(string angle, string direction)\r
{\r
- decimal raw = Decimal.Parse(angle);\r
+ decimal raw;\r
+ if (!Decimal.TryParse(angle, out raw))\r
+ {\r
+ return new Degree(Double.NaN);\r
+ }\r
double deg = (double)(Math.Floor(raw / 100m) + (raw % 100m) / 60m);\r
if (direction == "S" || direction == "W")\r
{\r
Degree.FromNmeaFormat(v[3], v[4]));\r
FixQuality = (FixQualityClass)Int32.Parse(v[5]);\r
TrackedSatellites = Int32.Parse(v[6]);\r
- Dilution = Decimal.Parse(v[7]);\r
- MslAltitude = GetLength(v[8], v[9]);\r
- GeoidSeparation = GetLength(v[10], v[11]);\r
+ HorizontalDop = ParseDouble(v[7]);\r
+ MslAltitude = new Height(GetLength(v[8], v[9]), \r
+ Height.Base.MeanSeaLevel);\r
+ GeoidSeparation = new Height(GetLength(v[10], v[11]),\r
+ Height.Base.Wgs84Ellipsoid);\r
+ double age = ParseDouble(v[12]);\r
\r
+ AgeOfDgpsCorrections = Double.IsNaN(age)?\r
+ TimeSpan.MinValue :TimeSpan.FromSeconds(age);\r
+ DgpsStation = ParseInt(v[13], -1);\r
CheckSum = elements.CheckSum;\r
}\r
\r
private set;\r
}\r
\r
- public decimal Dilution\r
+ public double HorizontalDop\r
{\r
get;\r
private set;\r
}\r
\r
- public decimal MslAltitude\r
+ public Height MslAltitude\r
{\r
get;\r
private set;\r
}\r
\r
- public decimal GeoidSeparation\r
+ public Height GeoidSeparation\r
{\r
get;\r
private set;\r
}\r
\r
- public int StationID\r
+ public TimeSpan AgeOfDgpsCorrections\r
+ {\r
+ get;\r
+ private set;\r
+ }\r
+\r
+ public int DgpsStation\r
{\r
get;\r
private set;\r
public int CheckSum;\r
public int PacketLength;\r
}\r
+\r
+ public enum Status\r
+ {\r
+ Unknown,\r
+ Invalid,\r
+ Valid,\r
+ }\r
#endregion\r
\r
#region fields\r
\r
protected static Elements GetElements(byte[] sentence, int elementNum)\r
{\r
- string[] values = new string[elementNum];\r
int elementIndex = 0;\r
int lastCommaPos = 6;\r
if (sentence[1] == 'G' && sentence[2] == 'P')\r
{\r
lastCommaPos = 7;\r
}\r
+ if (elementNum < 0)\r
+ {\r
+ elementNum = 0;\r
+ for (int i = lastCommaPos; i < sentence.Length; ++i)\r
+ {\r
+ if (sentence[i] == ',')\r
+ {\r
+ elementNum++;\r
+ continue;\r
+ }\r
+ if (sentence[i] == '*')\r
+ {\r
+ elementNum++;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ if (elementNum < 1)\r
+ {\r
+ return null;\r
+ }\r
+ string[] values = new string[elementNum];\r
for (int i = lastCommaPos; i < sentence.Length; ++i)\r
{\r
if (sentence[i] == ',' || sentence[i] == '*')\r
{\r
+ if (elementIndex >= elementNum)\r
+ {\r
+ return null;\r
+ }\r
values[elementIndex++] = Encoding.ASCII.GetString(\r
sentence, lastCommaPos, i - lastCommaPos);\r
lastCommaPos = i + 1;\r
}\r
return true;\r
}\r
+\r
protected TimeSpan ParseTime(string time)\r
{\r
int h = Int32.Parse(time.Substring(0, 2));\r
return new TimeSpan(0, h, m, sec, msec);\r
}\r
\r
- protected static decimal GetLength(string value, string unit)\r
+ protected static double GetLength(string value, string unit)\r
{ \r
- decimal v;\r
+ double v;\r
\r
- if (!Decimal.TryParse(value, out v))\r
+ if (!Double.TryParse(value, out v))\r
{\r
- return -Decimal.MaxValue;;\r
+ return Double.NaN;\r
}\r
if (unit == "M")\r
{\r
}\r
else\r
{\r
- return -Decimal.MaxValue; ;\r
+ return Double.NaN;\r
+ }\r
+ }\r
+\r
+ protected static int ParseInt(string intString, int defaultValue)\r
+ {\r
+ int v;\r
+ if (!Int32.TryParse(intString, out v))\r
+ {\r
+ return defaultValue;\r
+ }\r
+ return v;\r
+ }\r
+\r
+ protected static double ParseDouble(string doubleString)\r
+ {\r
+ return ParseDouble(doubleString, Double.NaN);\r
+ }\r
+ \r
+ protected static double ParseDouble(string doubleString,\r
+ double defaultValue)\r
+ {\r
+ double v;\r
+ if (!Double.TryParse(doubleString, out v))\r
+ {\r
+ return defaultValue;\r
+ }\r
+ return v;\r
+ }\r
+\r
+ protected static Status ParseStatus(string status)\r
+ {\r
+ switch (status)\r
+ {\r
+ case "V":\r
+ return Status.Invalid;\r
+ case "A":\r
+ return Status.Valid;\r
+ default:\r
+ return Status.Unknown;\r
}\r
}\r
#endregion\r