/// <summary> /// Process the data from a RMC /// </summary> /// <param name="data">String array of the message components for a RMC message.</param> public void Process(NmeaSentence sentence) { var position = new GnssPositionInfo(); position.TalkerID = sentence.TalkerID; position.TimeOfReading = NmeaUtilities.TimeOfReading(sentence.DataElements[8].ToString(), sentence.DataElements[0].ToString()); //Debug.WriteLine($"Time of Reading:{position.TimeOfReading}UTC"); if (sentence.DataElements[1].ToString().ToLower() == "a") { position.Valid = true; } else { position.Valid = false; } //Debug.WriteLine($"valid:{position.Valid}"); //if (position.Valid) { //Debug.WriteLine($"will attempt to parse latitude; element[2]:{sentence.DataElements[2]}, element[3]:{sentence.DataElements[3]}"); position.Position.Latitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[2].ToString(), sentence.DataElements[3].ToString()); //Debug.WriteLine($"will attempt to parse longitude; element[4]:{sentence.DataElements[4]}, element[5]:{sentence.DataElements[5]}"); position.Position.Longitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[4].ToString(), sentence.DataElements[5].ToString()); //Debug.WriteLine("40"); double speedInKnots; if (double.TryParse(sentence.DataElements[6].ToString(), out speedInKnots)) { position.SpeedInKnots = speedInKnots; } double courseHeading; if (double.TryParse(sentence.DataElements[7].ToString(), out courseHeading)) { position.CourseHeading = courseHeading; } if (sentence.DataElements[10].ToString().ToLower() == "e") { position.MagneticVariation = CardinalDirection.East; } else if (sentence.DataElements[10].ToString().ToLower() == "w") { position.MagneticVariation = CardinalDirection.West; } else { position.MagneticVariation = CardinalDirection.Unknown; } //} //Debug.WriteLine($"RMC Message Parsed, raising event"); PositionCourseAndTimeReceived(this, position); }
/// <summary> /// Process the data from a GLL message. /// </summary> /// <param name="data">String array of the message components for a GLL message.</param> public void Process(NmeaSentence sentence) { // // Status is stored in element 7 (position 6), A = valid, V = not valid. // var location = new GnssPositionInfo(); location.TalkerID = sentence.TalkerID; location.Position.Latitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[0].ToString(), sentence.DataElements[1].ToString()); location.Position.Longitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[2].ToString(), sentence.DataElements[3].ToString()); location.TimeOfReading = NmeaUtilities.TimeOfReading(null, sentence.DataElements[4].ToString()); location.Valid = (sentence.DataElements[5].ToString().ToLower() == "a"); GeographicLatitudeLongitudeReceived(this, location); }
/// <summary> /// Process the data from a GGA message. /// </summary> /// <param name="data">String array of the message components for a CGA message.</param> public void Process(NmeaSentence sentence) { // make sure all fields are present for (var index = 0; index <= 7; index++) { if (string.IsNullOrEmpty(sentence.DataElements[index].ToString())) { //Debug.WriteLine("Not all elements present"); // TODO: should we throw an exception and have callers wrap in a try/catch? // problem today is that it just quietly returns return; } } var location = new GnssPositionInfo(); location.TalkerID = sentence.TalkerID; location.TimeOfReading = NmeaUtilities.TimeOfReading(null, sentence.DataElements[0].ToString()); location.Position.Latitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[1].ToString(), sentence.DataElements[2].ToString()); location.Position.Longitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[3].ToString(), sentence.DataElements[4].ToString()); location.FixQuality = (FixType)Converters.Integer(sentence.DataElements[5].ToString()); int numberOfSatellites; if (int.TryParse(sentence.DataElements[6].ToString(), out numberOfSatellites)) { location.NumberOfSatellites = numberOfSatellites; } double horizontalDilutionOfPrecision; if (double.TryParse(sentence.DataElements[7].ToString(), out horizontalDilutionOfPrecision)) { location.HorizontalDilutionOfPrecision = horizontalDilutionOfPrecision; } double altitude; if (double.TryParse(sentence.DataElements[8].ToString(), out altitude)) { location.Position.Altitude = altitude; } PositionReceived(this, location); }