コード例 #1
0
ファイル: GpsReading.cs プロジェクト: junbao520/AndroidApp
        //=======================================================================

        //=======================================================================
        private static GpsReading ParseSentences(string[] sentences)
        {
            //---- declare vars
            GpsReading gpsReading = new GpsReading();

            //---- loop through each sentence
            foreach (var sentence in sentences.SelectMany(SpiltSentence))
            {
                //---- if the sentence has a header and data
                if (sentence != null && sentence.Length > 6)
                {
                    try
                    {
                        ParseSentence(gpsReading, sentence);
                    }
                    catch (Exception exp)
                    {
                        //Logger.ErrorFormat("解析Gps信号 {0} 发生异常", sentence, exp);
                    }
                }
            }

            //---- return our parsed gps reading
            return(gpsReading);
        }
コード例 #2
0
ファイル: GpsReading.cs プロジェクト: junbao520/AndroidApp
        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;
            }
        }