Logo Search packages:      
Sourcecode: gaia version File versions  Download package

int GPSSourceNMEA::ParseGPRMC ( char **  fields,
int  nfields,
GPSData target 
) [private]

Parse GPRMC (recommended minimum data) sentence

Parameters:
fields array of null-terminated strings containing sentence fields
nfields number of fields
target where to store coordinates in case of success
Returns:
1 if sentence was parsed successfully (i.e. *target valid), 0 otherwise

Definition at line 60 of file GPSSourceNMEA.cc.

References GPSData::latitude, and GPSData::longitude.

Referenced by ParseSentence().

                                                                         {
      /* need at least 6 fields */
      if (nfields < 6)
            return 0;

      /* drop reports marked as invalid */
      if (fields[1][0] == 'V')
            return 0;

      unsigned int i;
      double lat, lon, d;

      /* latitude */
      lat = (double)((fields[2][0]-'0')*10 + (fields[2][1]-'0'))*60.0;
      lat += (double)((fields[2][2]-'0')*10 + (fields[2][3]-'0'));

      for (i = 5, d = 0.1; i < strlen(fields[2]); i++, d /= 10.0)
            lat += (fields[2][i]-'0') * d;

      lat /= 360.0*60.0;

      if (fields[3][0] == 'S')
            lat *= -1.0;

      /* longitude */
      lon = (double)((fields[4][0]-'0')*100 + (fields[4][1]-'0')*10 + (fields[4][2]-'0'))*60.0;
      lon += (double)((fields[4][3]-'0')*10 + (fields[4][4]-'0'));

      for (i = 6, d = 0.1; i < strlen(fields[4]); i++, d /= 10.0)
            lon += (fields[4][i]-'0') * d;

      lon /= 360.0*60.0;

      if (fields[5][0] == 'W')
            lon *= -1.0;

      /* check */
      if (lat < -0.25 || lat > 0.25 || lon < -0.5 || lon > 0.5)
            return 0;

      target->longitude = lon;
      target->latitude = lat;
      return 1;
}


Generated by  Doxygen 1.6.0   Back to index