首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> 關於.NET

.NET Compact Framework 下 GPS NMEA 資料解析(下)

     編輯:關於.NET

GPGSV 解析

$GPGSV 訊息較特殊,將使用中衛星資訊分多句輸出:

$GPGSV,3,1,12,03,43,246,46,06,57,263,52,09,10,090,00,14,29,357,41*71
$GPGSV,3,2,12,15,12,140,00,16,10,307,00,18,59,140,00,19,20,224,00*75
$GPGSV,3,3,12,21,48,089,00,22,69,265,36,24,09,076,00,34,00,000,00*76

欄位說明:

  1. 總句數
  2. 當前句序號
  3. 可見衛星數
  4. 每組 4 欄位:衛星 ID、仰角、方位角、訊號強度 (SNR)

廠商私有 NMEA 句式同理依文件解析。完整 NmeaParser 類別程式碼:

public class NmeaParser {
    public struct Coordinate { public int Hours; public int Minutes; public double Seconds; }
    public enum FixStatus { NotSet, Obtained, Lost }
    public enum FixMode { Auto, Manual }
    public enum FixMethod { NotSet, Fix2D, Fix3D }
    public enum DifferentialGpsType { NotSet, SPS, DSPS, PPS, RTK }

    public class GpsSatellite {
        public int PRC { get; set; }
        public int Elevation { get; set; }
        public int Azimuth { get; set; }
        public int SNR { get; set; }
        public bool InUsed { get; set; }
        public bool InView { get; set; }
        public bool NotTracking { get; set; }
    }

    private static readonly CultureInfo NmeaCultureInfo = new CultureInfo("en-US");
    private static readonly decimal KMpHPerKnot = decimal.Parse("1.852", NmeaCultureInfo);

    private Coordinate latitude, longitude;
    private decimal altitude = 0;
    private DateTime utcDateTime;
    private decimal velocity = 0, azimuth = 0;
    private FixStatus fixStatus;
    private DifferentialGpsType differentialGpsType;
    private FixMode fixMode;
    private FixMethod fixMethod;
    private int satellitesInView, satellitesInUsed;
    private readonly Dictionary<int, GpsSatellite> satellites;
    private decimal horizontalDilutionOfPrecision = 50, positionDilutionOfPrecision = 50, verticalDilutionOfPrecision = 50;

    public NmeaParser() { satellites = new Dictionary<int, GpsSatellite>(); }

    public bool Parse(string sentence) {
        string rawData = sentence;
        try {
            if (!IsValid(sentence)) return false;
            sentence = sentence.Substring(1, sentence.IndexOf('*') - 1);
            string[] words = GetWords(sentence);
            switch (words[0]) {
                case "GPRMC": return ParseGPRMC(words);
                case "GPGGA": return ParseGPGGA(words);
                case "GPGSA": return ParseGPGSA(words);
                case "GPGSV": return ParseGPGSV(words);
                default: return false;
            }
        } catch (Exception e) { Console.WriteLine(e.Message + rawData); return false; }
    }

    private bool IsValid(string sentence) { ... }
    private bool Checksum(string sentence, string checksumStr) { ... }
    private static string[] GetWords(string sentence) { return sentence.Split(','); }

    private bool ParseGPRMC(string[] words) { ... }
    private bool ParseGPGGA(string[] words) { ... }
    private bool ParseGPGSA(string[] words) { ... }
    private bool ParseGPGSV(string[] words) { ... }
}

(完整方法實作包含座標解析、校驗和衛星資訊填充,詳見原始碼)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved