Windows mobile gps 串口通信 NMEA命令和数据处理
2010-06-22 03:15:00 来源:WEB开发网GPRMC.Month = Convert.ToInt32(fields[8].Substring(2, 2));
GPRMC.Year = Convert.ToInt32(fields[8].Substring(4, 2));
GPRMC.DataValid = Convert.ToChar(fields[1]);
//Latitude
GPRMC.Latitude = Convert.ToDouble(fields[2]) / 100;
if (fields[3] == "S")
GPRMC.LatitudeHemisphere = Cardinal.South;
else
GPRMC.LatitudeHemisphere = Cardinal.North;
//Longitude
GPRMC.Longitude = Convert.ToDouble(fields[4]) / 100;
if (fields[5] == "E")
GPRMC.LatitudeHemisphere = Cardinal.East;
else
GPRMC.LatitudeHemisphere = Cardinal.West;
GPRMC.GroundSpeed = Convert.ToDouble(fields[6]);
//TODO: MagVar and Course
GPRMC.Count++;
}
public void ProcessGPGSV(string data)
{
//parses the GPGSV stream to extract satellite information
string[] fields = Regex.Split(data,",");
uint totalNumberOfMessages = Convert.ToUInt32(fields[0]);
//make sure the data is OK. valid range is 1..8 channels
if ((totalNumberOfMessages > 8) || (totalNumberOfMessages <= 0))
return;
GPGSV.TotalNumberOfMessages = totalNumberOfMessages;
//message number
int nMessageNumber = Convert.ToInt32(fields[1]);
//make sure it is 0..9...is there an inconsistency? 8/9?
if ((nMessageNumber > 9) || (nMessageNumber < 0))
return;
//sats in view
GPGSV.SatellitesInView = Convert.ToInt32(fields[2]);
//for(int iSat = 0; iSat < GPGSV.SatellitesInView; iSat++)
for (int iSat = 0; iSat < 4; iSat++)
{
Satellite sat = new Satellite();
sat.Id = Convert.ToInt32(fields[3+iSat*4]);
sat.Elevation = Convert.ToInt32(fields[4+iSat*4]);
sat.Azimuth = Convert.ToInt32(fields[5+iSat*4]);
更多精彩
赞助商链接