Exemple #1
0
        public static HgaData 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(',');

            HgaData data = new HgaData();

            data.OriginalSentence = inputString;
            data.FormatedSentence = sentence;
            //NovAtel Status
            data.FixStatus = NAFixStatus.None;
            if (words.Length >= 2 && words[1].Length != 0)
            {
                try
                {
                    data.FixStatus = (NAFixStatus)Enum.Parse(typeof(NAFixStatus), words[1], true);
                }
                catch (Exception ex)
                {
                    string str = ex.Message;
                }
            }

            data.Baseline = ParseWord(words, 2, double.Parse, 0);
            // The bearing is the seventh word
            data.BearingDegrees = ParseWord(words, 3, double.Parse, 0);
            // The elevation is the seventh word
            data.ElevationDegrees     = ParseWord(words, 4, double.Parse, 0);
            data.SatellitesInTrack    = ParseWord(words, 9, int.Parse, 0);
            data.SatellitesInSolution = ParseWord(words, 10, int.Parse, 0);

            return(data);
        }
Exemple #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;
            }
        }