Example #1
0
        public static UtmData Parse(string inputString)
        {
            if (string.IsNullOrEmpty(inputString) || !inputString.StartsWith("#"))
            {
                return(null);
            }

            var startIndex = inputString.IndexOf(";", StringComparison.Ordinal);

            if (startIndex < 0)
            {
                return(null);
            }
            var endIndex = inputString.IndexOf("*", StringComparison.Ordinal);

            if (endIndex < 0)
            {
                return(null);
            }

            var sentence = inputString.Substring(startIndex, endIndex - startIndex);
            var words    = sentence.Split(',');

            UtmData data = new UtmData();

            data.OriginalSentence = inputString;
            data.FormatedSentence = sentence;
            //NovAtel Status
            var fixStatus = NAFixStatus.None;

            if (words.Length >= 2 && words[1].Length != 0)
            {
                Enum.TryParse(words[1], true, out fixStatus);
            }

            data.FixStatus            = fixStatus;
            data.Northing             = ParseWord(words, 4, double.Parse, 0);
            data.Easting              = ParseWord(words, 5, double.Parse, 0);
            data.Elevation            = ParseWord(words, 6, double.Parse, 0);
            data.SatellitesInTrack    = ParseWord(words, 15, int.Parse, 0);
            data.SatellitesInSolution = ParseWord(words, 18, int.Parse, 0);

            return(data);
        }
Example #2
0
        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;
            }
        }