bool ubloxNMEA::parsePUBX_00( char chr )
{
  bool ok = true;

  switch (fieldIndex) {
    case 1:
      // The first field is actually a message subtype
      if (chrCount == 0)
        ok = (chr == '0');

      else if (chrCount == 1) {
        switch (chr) {
          #if defined(NMEAGPS_PARSE_PUBX_00) | defined(NMEAGPS_RECOGNIZE_ALL)
            case '0': break;
          #endif
          #if defined(NMEAGPS_PARSE_PUBX_04) | defined(NMEAGPS_RECOGNIZE_ALL)
            case '4': nmeaMessage = (nmea_msg_t) PUBX_04; break;
          #endif
          default : ok = false;
        }

      } else // chrCount > 1
        ok = (chr == ',');
      break;

    #ifdef NMEAGPS_PARSE_PUBX_00
      case  2: return parseTime( chr );
      PARSE_LOC(3);
      case  7: return parseAlt( chr );
      case  8: return parseFix( chr );
      case 11: return parseSpeed( chr ); // kph!
      case 12: return parseHeading( chr );
      case 15: return parseHDOP( chr );
      case 16: return parseVDOP( chr );
      case 18: return parseSatellites( chr );
    #endif
  }

  return ok;

} // parsePUBX_00
Exemplo n.º 2
0
bool ubloxNMEA::parsePUBX_00( char chr )
{
  bool ok = true;

  switch (fieldIndex) {
    case 1:
      // The first field is actually a message subtype
      if (chrCount == 0)
        ok = (chr == '0');

      else if (chrCount == 1) {
        switch (chr) {
          #if defined(NMEAGPS_PARSE_PUBX_00) | defined(NMEAGPS_RECOGNIZE_ALL)
            case '0': break;
          #endif
          #if defined(NMEAGPS_PARSE_PUBX_04) | defined(NMEAGPS_RECOGNIZE_ALL)
            case '4': nmeaMessage = (nmea_msg_t) PUBX_04; break;
          #endif
          default : ok = false;
        }

      } else // chrCount > 1
        ok = (chr == ',');
      break;

    #ifdef NMEAGPS_PARSE_PUBX_00
      case  2: return parseTime( chr );
      PARSE_LOC(3);
      case  7: return parseAlt( chr );
      case  8: return parseFix( chr );
      case  9: // use Horizontal accuracy for both lat and lon errors
        #if defined(GPS_FIX_LAT_ERR)
          ok = parse_lat_err( chr );
          #if defined(GPS_FIX_LON_ERR)
            // When the lat_err field is finished,
            //   copy it to the lon_err field.
            if (chr == ',') {
              m_fix.valid.lon_err = m_fix.valid.lat_err;
              if (m_fix.valid.lon_err)
                m_fix.lon_err_cm = m_fix.lat_err_cm;
            }
          #endif

        #elif defined(GPS_FIX_LON_ERR)
          ok = parse_lon_err( chr );
        #endif
        break;
      case 10: return parse_alt_err( chr ); // vertical accuracy
      case 11:
        #ifdef GPS_FIX_SPEED
          ok = parseSpeed( chr ); // PUBX,00 provides speed in km/h!

          if ((chr == ',') && m_fix.valid.speed) {
            uint32_t kph    = m_fix.spd.int32_000();
            uint32_t nmiph  = (kph * 1000) / gps_fix::M_PER_NMI;
            m_fix.spd.whole = nmiph / 1000;
            m_fix.spd.frac  = (nmiph - m_fix.spd.whole*1000);
            // Convert to Nautical Miles/Hour
          }
        #endif
        break;
      case 12: return parseHeading( chr );
      case 13: return parseVelocityDown( chr );
      case 15: return parseHDOP( chr );
      case 16: return parseVDOP( chr );
      case 18: return parseSatellites( chr );
    #endif
  }

  return ok;

} // parsePUBX_00
Exemplo n.º 3
0
/*****************************************************************************
 ** Function name:               GPSRetreiveData
 **
 ** Descriptions:                Reads and parses the next set of GPS data.
 **
 ** parameters:                  None
 ** Returned value:              The parsed information
 **
 *****************************************************************************/
const gpsData* GPSRetreiveData(void)
{
	uint8_t * pattern = (uint8_t*)"GPGGA";

	while (1) {
		uint8_t buf[100];
		uint8_t ch = 0;
		uint8_t *ptr = 0;
		int index = 0;

		// Retrieve the first byte
		if (!UARTGetChar(&ch))
			continue;

		 // look for "$GPGGA," header
		if (ch != '$') {
			continue;
		}

		// Retrieve the next six bytes
		for (index=0; index<6; index++) {
			buf[index] = UARTGetCharBlock();
		}

		//Check if its Global Positioning System fixed Data
		if(hasPattern((uint8_t*)&buf, pattern) == 0) {
			continue;
		}

		//Retrieve the data from the GPS module
		for (index=0; index<100; index++) {
			buf[index] = UARTGetCharBlock();

			if (buf[index] == '\r') {
				buf[index] = END_OF_MESSAGE;
				break;
			}
		}

		ptr = &buf[0];

		//parse UTC time
		parseUTC(&ptr);

		//parse Latitude
		parseLatitude(&ptr);

		// parse N/S field
		parseNSIndicator(&ptr);

		// parse Longitude
		parseLongitude(&ptr);

		// parse E/W field
		parseEWIndicator(&ptr);

		// parse fix position
		parseFixIndicator(&ptr);

		// parse satellites
		parseSatellites(&ptr);

		// parse horizontal-dilution-of-precision field
		parseHDOP(&ptr);

		// parse altitude
		parseAltitudes(&ptr);

		break;
	}
	return &data;
}