$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
欄位說明:
廠商私有 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) { ... }
}
(完整方法實作包含座標解析、校驗和衛星資訊填充,詳見原始碼)