public static VtgData Parser(string inputString) { VtgData data = new VtgData(); if (inputString == null || inputString.Length == 0) { return(data); } string dataString = inputString; if (inputString.Contains("*")) { dataString = inputString.Substring(0, inputString.IndexOf('*')); // strip off the checksum } else { return(data); } string[] values = dataString.Split(','); if (values.Length < 10) { return(data); //throw new FormatException(); } if (string.Compare(values[9], "a", true) == 0) { data.Mode = GpsMode.Autonomous; } else if (string.Compare(values[9], "d", true) == 0) { data.Mode = GpsMode.DifferentialGPS; } else { data.Mode = GpsMode.DR; } string speed = values[7]; if (speed == null || speed.Length == 0) { speed = "0.0"; } data.GroundSpeedInKmh = double.Parse(speed); speed = values[5]; if (speed == null || speed.Length == 0) { speed = "0.0"; } data.GroundSpeedInKnots = decimal.Parse(speed); return(data); }
private static void ParseSentence(GpsReading gpsReading, string sentence) { var cmd = ParseCommand(sentence); if (string.IsNullOrEmpty(cmd)) { return; } //GPNTR switch (cmd.ToUpper()) { case "$GPGGA": case "$GNGGA": case "$BDGGA": gpsReading.FixedGpsData = GgaData.Parse(sentence); break; case "$GPVTG": case "$GNVTG": case "$BDVTG": gpsReading.GroundVector = VtgData.Parser(sentence); break; case "$GPRMC": case "$GNRMC": case "$BDRMC": gpsReading.Summary = RmcData.Parse(sentence); break; case "#HEADINGA": gpsReading.Heading = HgaData.Parse(sentence); break; case "#BESTUTMA": gpsReading.Utm = UtmData.Parse(sentence); break; case "$GPNTR": gpsReading.NtrData = NtrData.Parse(sentence); break; //case "$GPGSA": // gpsReading.DopActiveSatellites = GsaData.Parse(sentence); // break; //case "$GPGSV": // gpsReading.SatellitesInView.Add(GsvData.Parse(sentence)); // break; //case "$GPHDT": // gpsReading.HdtData = HdtData.Parse(sentence); // break; case "$PTNL": if (sentence.IndexOf("AVR", System.StringComparison.Ordinal) > 0) { gpsReading.AvrData = AvrData.Parse(sentence); } else if (sentence.IndexOf("VGK", System.StringComparison.Ordinal) > 0) { gpsReading.VgkData = VgkData.Parse(sentence); } break; } }