/// <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], sentence.DataElements[0]); //Console.WriteLine($"Time of Reading:{position.TimeOfReading}UTC"); if (sentence.DataElements[1].ToLower() == "a") { position.Valid = true; } else { position.Valid = false; } //Console.WriteLine($"valid:{position.Valid}"); //if (position.Valid) { //Console.WriteLine($"will attempt to parse latitude; element[2]:{sentence.DataElements[2]}, element[3]:{sentence.DataElements[3]}"); position.Position.Latitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[2], sentence.DataElements[3]); //Console.WriteLine($"will attempt to parse longitude; element[4]:{sentence.DataElements[4]}, element[5]:{sentence.DataElements[5]}"); position.Position.Longitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[4], sentence.DataElements[5]); //Console.WriteLine("40"); decimal speedInKnots; if (decimal.TryParse(sentence.DataElements[6], out speedInKnots)) { position.SpeedInKnots = speedInKnots; } decimal courseHeading; if (decimal.TryParse(sentence.DataElements[7], out courseHeading)) { position.CourseHeading = courseHeading; } if (sentence.DataElements[10].ToLower() == "e") { position.MagneticVariation = CardinalDirection.East; } else if (sentence.DataElements[10].ToLower() == "w") { position.MagneticVariation = CardinalDirection.West; } else { position.MagneticVariation = CardinalDirection.Unknown; } //} //Console.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], sentence.DataElements[1]); location.Position.Longitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[2], sentence.DataElements[3]); location.TimeOfReading = NmeaUtilities.TimeOfReading(null, sentence.DataElements[4]); location.Valid = (sentence.DataElements[5].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])) { //Console.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]); location.Position.Latitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[1], sentence.DataElements[2]); location.Position.Longitude = NmeaUtilities.DegreesMinutesDecode(sentence.DataElements[3], sentence.DataElements[4]); location.FixQuality = (FixType)Converters.Integer(sentence.DataElements[5]); int numberOfSatellites; if (int.TryParse(sentence.DataElements[6], out numberOfSatellites)) { location.NumberOfSatellites = numberOfSatellites; } decimal horizontalDilutionOfPrecision; if (decimal.TryParse(sentence.DataElements[7], out horizontalDilutionOfPrecision)) { location.HorizontalDilutionOfPrecision = horizontalDilutionOfPrecision; } decimal altitude; if (decimal.TryParse(sentence.DataElements[8], out altitude)) { location.Position.Altitude = altitude; } PositionReceived(this, location); }