.NET Compact Framework下的GPS NMEA data数据分析(下)2010-11-22 博客园 Jake.NET代码5从ParseGPGSA看,这个比较特别,他把在使用的卫星信息分开 多条语句output。如下:$GPGSV,3,1,12,03,43,246,46,06,57,263,52,09,10,090,00,14,2 9,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为卫星的ID,字段5为太空海拔,字段6为角度,字段7为信号强弱 。对于厂商的私有NMEA data也是同样的方法进行分析,根据文档的描述 进行分析。下面为整个类的代码。NmeaParser public class NmeaParser { public struct Coordinate { public int Hours; public int Minutes; public double Seconds; }
public enum FixStatus { NotSet, Obtained, //A Lost //V }
public enum FixMode { Auto, //A 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 bool Checksum (string sentence, string checksumStr) { int checksum = 0; int length = sentence.IndexOf("*") - 1; // go from first character upto last * for (int i = 1; i <= length; ++i) { checksum = checksum ^ Convert.ToByte (sentence[i]); }
// Divides a sentence into individual Words private static string[] Getwords(string sentence) { return sentence.Split(","); }
private bool ParseGPRMC (string[] Words) { if (Words[1].Length > 0 & Words [9].Length > 0) { int UtcHours = Convert.ToInt32(Words [1].Substring(0, 2)); int UtcMinutes = Convert.ToInt32(Words [1].Substring(2, 2)); int UtcSeconds = Convert.ToInt32(Words [1].Substring(4, 2)); int UtcMilliseconds = 0;
// Extract milliseconds if it is available if (Words[1].Length > 7) { UtcMilliseconds = Convert.ToInt32(Words[1].Substring(7)); }
int UtcDay = Convert.ToInt32(Words[9].Substring(0, 2)); int UtcMonth = Convert.ToInt32(Words [9].Substring(2, 2)); // available for this century int UtcYear = Convert.ToInt32(Words [9].Substring(4, 2)) + 2000;