Exemplo n.º 1
0
        public override void Parse(string nmeaLine)
        {
            if (string.IsNullOrWhiteSpace(nmeaLine) ||
                !nmeaLine.StartsWith($"${Type}"))
            {
                throw new NmeaParseMismatchException();
            }

            ParseChecksum(nmeaLine);

            if (MandatoryChecksum != ExtractChecksum(nmeaLine))
            {
                throw new NmeaParseChecksumException();
            }

            // remove identifier plus first comma
            var sentence = nmeaLine.Remove(0, $"${Type}".Length + 1);

            // remove checksum and star
            sentence = sentence.Remove(sentence.IndexOf('*'));

            var items = sentence.Split(',');

            TrueTrackMadeGood            = items[0] + items[1];
            MagneticTrackMadeGood        = items[2] + items[3];
            GroundSpeedKnots             = items[4] + items[5];
            GroundSpeedKilometersPerHour = items[6] + items[7];

            ModeIndicator = items.Length > 8
                ? new ModeIndicator(items[8])
                : new ModeIndicator("");

            OnNmeaMessageParsed(this);
        }
Exemplo n.º 2
0
        public override void Parse(string nmeaLine)
        {
            if (string.IsNullOrWhiteSpace(nmeaLine) ||
                !nmeaLine.StartsWith($"${Type}"))
            {
                throw new NmeaParseMismatchException();
            }

            ParseChecksum(nmeaLine);

            if (MandatoryChecksum != ExtractChecksum(nmeaLine))
            {
                throw new NmeaParseChecksumException();
            }

            // remove identifier plus first comma
            var sentence = nmeaLine.Remove(0, $"${Type}".Length + 1);

            // remove checksum and star
            sentence = sentence.Remove(sentence.IndexOf('*'));

            var items = sentence.Split(',');

            Latitude  = new Location(items[0] + items[1]);
            Longitude = new Location(items[2] + items[3]);
            FixTaken  = items[4];
            DataValid = items[5];

            ModeIndicator = items.Length > 6
                ? new ModeIndicator(items[6])
                : new ModeIndicator("");

            OnNmeaMessageParsed(this);
        }