/// <summary> /// Parses an RMC sentence which has the following format: /// RMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68 /// </summary> /// <param name="tokens">Tokens from the NMEA string in order </param> /// <param name="newNmeaBurst">NmeaBurst to add the data to </param> private void ParseRMC(String[] tokens, ref NmeaBurst toFill) { try { if (tokens[1] != string.Empty) { if (tokens[1].Length > 6) tokens[1] = tokens[1].Substring(0, 6); toFill._time = DateTime.ParseExact(tokens[1], "HHmmss", System.Globalization.CultureInfo.CurrentCulture); } if (tokens[3].IsDouble()) toFill._RMC_latitude = Convert.ToDouble(tokens[3]); if (tokens[4] != String.Empty) toFill._RMC_latDir = CoordConvert.ConvertNorthSouth(tokens[4]);// (NorthSouth)Enum.Parse(typeof(NorthSouth), tokens[4], true); if (tokens[5].IsDouble()) toFill._RMC_longitude = Convert.ToDouble(tokens[5]); if (tokens[6] != String.Empty) toFill._RMC_longDir = CoordConvert.ConvertEastWest(tokens[6]);// (EastWest)Enum.Parse(typeof(EastWest), tokens[6], true); if (tokens[7].IsDouble()) toFill._track_angle = Convert.ToDouble(tokens[7]); if (tokens[8].IsDouble()) toFill._speed = Convert.ToDouble(tokens[8]); if (tokens[9] != String.Empty) { if (tokens[9].Length > 6) tokens[9] = tokens[9].Substring(0, 6); toFill._date = DateTime.ParseExact(tokens[9], "ddMMyy", System.Globalization.CultureInfo.CurrentCulture); } if (tokens[10].IsDouble()) toFill._magVar = Convert.ToDouble(tokens[10]); if (tokens[11] != String.Empty) toFill._magVarDir = CoordConvert.ConvertEastWest(tokens[11]);// (EastWest)Enum.Parse(typeof(EastWest), tokens[11], true); toFill.bRMC = true; } catch { toFill.BadData(); } }
private void ParseGSA(String[] tokens, ref NmeaBurst toFill) { try { StringBuilder sb = new StringBuilder(); if (tokens[2].IsInteger()) toFill._fix = Convert.ToInt32(tokens[2]); for (int i = 3; i < 15; i++) { if (tokens[i] != "") sb.Append(tokens[i] + '_'); } toFill._fixed_PRNs = sb.ToString(); toFill._fixed_PRNs.TrimEnd('_'); if (tokens[15].IsDouble()) toFill._PDOP = Convert.ToDouble(tokens[15]); if (tokens[16].IsDouble()) toFill._HDOP = Convert.ToDouble(tokens[16]); if (tokens[16].IsDouble()) toFill._VDOP = Convert.ToDouble(tokens[17]); toFill.bGSA = true; } catch { toFill.BadData(); } }
/// <summary> /// Parses a GSV sentence /// </summary> /// <param name="tokens">String tokens from the NMEA sentence</param> /// <param name="toFill">NmeaBurst to put the sentence data into</param> private void ParseGSV(String[] tokens, ref NmeaBurst toFill) { try { if (tokens[1] != String.Empty && toFill.totalGSV < 0) { if (tokens[1].IsInteger()) toFill.totalGSV = Convert.ToInt32(tokens[1]); if (tokens[3].IsInteger()) toFill._num_of_sat = Convert.ToInt32(tokens[3]); } for (int i = 4; i < tokens.Length - 4; i += 4) { Satellite s = new Satellite(); if (tokens[i] != String.Empty) s.ID = tokens[i]; if (tokens[i + 1].IsDouble()) s.Elevation = Convert.ToDouble(tokens[i + 1]); if (tokens[i + 2].IsDouble()) s.Azimuth = Convert.ToDouble(tokens[i + 2]); if (tokens[i + 3].IsDouble()) s.SNR = Convert.ToDouble(tokens[i + 3]); toFill.AddSatalite(s); } toFill.countGSV++; //if all GSV sentences parsed mark as GSV completed if (toFill.countGSV >= toFill.totalGSV) toFill.bGSV = true; } catch { toFill.BadData(); } }
private void ParseGGA(String[] tokens, ref NmeaBurst toFill) { try { if (tokens[2].IsDouble()) toFill._GGA_latitude = Convert.ToDouble(tokens[2]); if (tokens[3] != String.Empty) toFill._GGA_latDir = CoordConvert.ConvertNorthSouth(tokens[3]);// (NorthSouth)Enum.Parse(typeof(NorthSouth), tokens[3], true); if (tokens[4].IsDouble()) toFill._GGA_longitude = Convert.ToDouble(tokens[4]); if (tokens[5] != String.Empty) toFill._GGA_longDir = CoordConvert.ConvertEastWest(tokens[5]);// (EastWest)Enum.Parse(typeof(EastWest), tokens[5], true); if (tokens[6].IsInteger()) toFill._fix_quality = Convert.ToInt32(tokens[6]); if (tokens[7].IsInteger()) toFill._num_of_used_sat = Convert.ToInt32(tokens[7]); if (tokens[8].IsDouble()) toFill._horiz_dilution_position = Convert.ToDouble(tokens[8]); if (tokens[9].IsDouble()) toFill._altitude = Convert.ToDouble(tokens[9]); if (tokens[10] != String.Empty) toFill._alt_unit = TtUtils.ConvertUnit(tokens[10]);// (Unit)Enum.Parse(typeof(Unit), tokens[10], true); if (tokens[11].IsDouble()) toFill._geoid_height = Convert.ToDouble(tokens[11]); if (tokens[12] != String.Empty) toFill._geoid_unit = TtUtils.ConvertUnit(tokens[12]);// (Unit)Enum.Parse(typeof(Unit), tokens[12], true); toFill.bGGA = true; } catch { toFill.BadData(); } }