// // Copyright (c) 2014 Morten Nielsen // // Licensed under the Microsoft Public License (Ms-PL) (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://opensource.org/licenses/Ms-PL.html // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NmeaParser.Nmea.Gps { /// /// Routes /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gprte")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] [NmeaMessageType("GPRTE")] public sealed class Gprte : NmeaMessage, IMultiPartMessage { /// /// Waypoint tpe /// public enum WaypointListType { /// /// Complete list of waypoints /// CompleteWaypointsList, /// /// List of remaining waypoints /// RemainingWaypointsList } /// /// Called when the message is being loaded. /// /// The NMEA message values. protected override void OnLoadMessage(string[] message) { if (message == null || message.Length < 4) throw new ArgumentException("Invalid GPRTE", "message"); TotalMessages = int.Parse(message[0], CultureInfo.InvariantCulture); MessageNumber = int.Parse(message[1], CultureInfo.InvariantCulture); ListType = message[2] == "c" ? WaypointListType.CompleteWaypointsList : WaypointListType.RemainingWaypointsList; RouteId = message[3]; Waypoints = message.Skip(4).ToArray(); } /// /// Total number of messages of this type in this cycle /// public int TotalMessages { get; private set; } /// /// Message number /// public int MessageNumber { get; private set; } /// /// Gets the type of the list. /// public WaypointListType ListType { get; private set; } /// /// Gets the route identifier. /// public string RouteId { get; private set; } /// /// Waypoints /// public IReadOnlyList Waypoints { get; private set; } /// /// Returns an enumerator that iterates through the collection. /// /// A System.Collections.Generic.IEnumerator{T} that can be used to iterate through the collection. IEnumerator IEnumerable.GetEnumerator() { foreach (string waypoint in Waypoints) yield return waypoint; } /// /// Returns an enumerator that iterates through a collection. /// /// An System.Collections.IEnumerator object that can be used to iterate through the collection. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } }